[Haskell-cafe] Teaching Haskell

2006-06-01 Thread Walter Potter

All,

Is there a list for those of us who teach Haskell ?

Or should teaching questions be posted here?

Thanks, Walt

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Eclipse and Haskell

2006-06-01 Thread Walter Potter

All,

I intend to start using Eclipse as my IDE. Please pass along any  
suggestions that I may find useful.


Thanks, Walt
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Efficient way to edit a file

2006-06-01 Thread Donald Bruce Stewart
dons:
> briqueabraque:
> >   Hi,
> > 
> >   I need to edit big text files (5 to 500 Mb). But I just need to 
> > change one or two small lines, and save it. What is the best way to do 
> > that in Haskell, without creating copies of the whole files?
> > 

Thinking further, since you want to avoid copying on the disk, you need
to be able to keep the edited version in memory. So the strict
bytestring would be best, for example:

import System.Environment
import qualified Data.ByteString.Char8 as B

main = do
[f] <- getArgs
B.writeFile f . B.unlines . map edit . B.lines =<< B.readFile f

where
edit :: B.ByteString -> B.ByteString
edit s | (B.pack "Instances") `B.isPrefixOf` s = B.pack "EDIT"
   | otherwise = s

Edits a 100M file in

$ ghc -O -funbox-strict-fields A.hs -package fps 
$ time ./a.out /home/dons/data/100M
./a.out /home/dons/data/100M  1.54s user 0.76s system 13% cpu 17.371 total

You could probably tune this further.

-- Don
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Efficient way to edit a file

2006-06-01 Thread Donald Bruce Stewart
dons:
> briqueabraque:
> >   Hi,
> > 
> >   I need to edit big text files (5 to 500 Mb). But I just need to 
> > change one or two small lines, and save it. What is the best way to do 
> > that in Haskell, without creating copies of the whole files?
> > 
> 
> I'd think maybe a lazy bytestring would be ok.
> 
> Something like:
>   import Data.ByteString.Lazy.Char8
>   B.putStr . B.unlines . B.map edit . B.lines =<< B.getContents
> 
> in the darcs version of Data.ByteString, here, 
> http://www.cse.unsw.edu.au/~dons/fps.html
> Let me know how you go, it would make a good benchmark.

Oh, of course, if you actually don't want to copy the file, you'll need
to strictly read the input file, in order to write over it safely.

- Don
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Efficient way to edit a file

2006-06-01 Thread Donald Bruce Stewart
briqueabraque:
>   Hi,
> 
>   I need to edit big text files (5 to 500 Mb). But I just need to 
> change one or two small lines, and save it. What is the best way to do 
> that in Haskell, without creating copies of the whole files?
> 

I'd think maybe a lazy bytestring would be ok.

Something like:
  import Data.ByteString.Lazy.Char8
  B.putStr . B.unlines . B.map edit . B.lines =<< B.getContents

in the darcs version of Data.ByteString, here, 
http://www.cse.unsw.edu.au/~dons/fps.html
Let me know how you go, it would make a good benchmark.

-- Don

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Efficient way to edit a file

2006-06-01 Thread MaurĂ­cio

  Hi,

  I need to edit big text files (5 to 500 Mb). But I just need to 
change one or two small lines, and save it. What is the best way to do 
that in Haskell, without creating copies of the whole files?


  Thanks,
  MaurĂ­cio

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Tips for converting Prolog to typeclasses?

2006-06-01 Thread Greg Buchholz
Robert Dockins wrote:
] In the second instance, what you really want to say is "instance c [a]
] c, only where c is not an application of (->)".  As I recall, there is
] a way to express such type equality/unequality using typeclasses, but
] I don't remember how to do it offhand.

For those playing along at home, here's the less general version
which uses Oleg Kiselyov's "IsFunction" relation and associated TypeCast
machinery from the HList paper...

> {-# OPTIONS -fglasgow-exts #-} 
> {-# OPTIONS -fallow-undecidable-instances #-}
> 
> data HTrue
> data HFalse
> 
> class IsFunction a b | a -> b
> instance TypeCast f HTrue => IsFunction (x->y) f
> instance TypeCast f HFalse => IsFunction a f
> 
> class TypeCast   a b   | a -> b, b->a   where typeCast   :: a -> b
> class TypeCast'  t a b | t a -> b, t b -> a where typeCast'  :: t->a->b
> class TypeCast'' t a b | t a -> b, t b -> a where typeCast'' :: t->a->b
> instance TypeCast'  () a b => TypeCast a b where typeCast x = typeCast' () x
> instance TypeCast'' t a b => TypeCast' t a b where typeCast' = typeCast''
> instance TypeCast'' () a a where typeCast'' _ x  = x
> 
> class Apply a b c where -- | a b -> c where
> apply :: a -> b -> c
> 
> instance Apply b [a] c => Apply (a->b) [a] c where
> apply f [] = error "Not enough arguments"
> apply f (x:xs) = apply (f x) xs
> 
> instance IsFunction c HFalse => Apply c [a] c where
> apply f _ = f
> 
> main = do print (apply g [(1::Int)..] ::String)
>   
> g :: Int -> Int -> Int -> Int -> String
> g w x y z = show $ w*x + y*z 

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Bytes to float

2006-06-01 Thread Ivan Tikhonov
Hello.

I have 4 bytes long String and i want to convert it to Float.
How can i do this in Haskell? Don't want to use Ptr's.

Thanks.

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Filtering on data constructors with TH

2006-06-01 Thread Evan Martin

On 6/1/06, Christophe Poucet <[EMAIL PROTECTED]> wrote:

That's why
today I have created an automated derivation for data constructor
filtering. As I started coding someone mentioned that something similar
can be done with list comprehensions, so I'm not certain about the scope
of usefulness, however personally I have found the need for this at
times.


data T = A Int | B String deriving Show
test1 = [A 3, B "hello", A 5]
test2 = [x | x@(A _) <- test1]

The key here is that pattern match failure in a monad calls fail:
http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#v%3Afail
and fail in the List monad is [].
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Tips for converting Prolog to typeclasses?

2006-06-01 Thread Greg Buchholz
Robert Dockins wrote:
> 
> To make this work, you're going to have to convince the compiler to accept 
> "overlapping instances" and then make sure they don't overlap :) In the 
> second instance, what you really want to say is "instance c [a] c, only where 
> c is not an application of (->)".  As I recall, there is a way to express 
> such type equality/unequality using typeclasses, but I don't remember how to 
> do it offhand.

Now that I think about it more, I see what you are saying.  And I
think we can be a little more general than "c is not an application of
(->)".  A better statement might be "c is not a function application
which takes an 'a' as the first argument".  That should allow us to have
a function of type Int->Int->Double->String return a function
Double->String when applied to a list of Int's.  So in Prolog...

:- op(1000,xfy,=>).

app(A=>B,[A],C) :- app(B,[A],C).
app(C,[A],C) :- not(isfuncwithhead(C,A)).

isfuncwithhead(A=>B,A).

...Now I just need to figure out how to represent "not" without "cut".
I'll take a look at what Oleg has done.

Thanks,

Greg Buchholz
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: [Haskell] My summer of code project: HsJudy

2006-06-01 Thread Simon Marlow

Bulat Ziganshin wrote:


Thursday, June 1, 2006, 2:13:03 PM, you wrote:



Bulat Ziganshin wrote:



1. In terms of Haskell, Judy is a library of _mutable_ collections of
_unboxed_ elements. i pointed you to the Array wiki page, where
differences between boxed and unboxed, mutable and immutable
datastructures are described



There's no reason you can't use Judy to implement immutable collections,
just as we use mutable arrays to implement immutable ones.
 
if you mean Data.Array.Base module (not Data.Array.Diff), then mutable

arrays used there only to _initialize_ immutable ones


Yes of course.  I'm objecting to your comment above, which implies that 
because Judy implements mutable collections, that is how they must be 
presented to the Haskell programmer.  That simply isn't the case, you 
can certainly use Judy as the substrate for an immutable collection type 
in Haskell.  Augmenting the collection might be inefficient, but that 
depends on how you implement it, just like arrays.  It would be 
appropriate in cases where you initialize a collection once, and then 
access it many times.


Cheers,
Simon
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re[2]: [Haskell] My summer of code project: HsJudy

2006-06-01 Thread Bulat Ziganshin
Hello Simon,

Thursday, June 1, 2006, 2:13:03 PM, you wrote:

> Bulat Ziganshin wrote:

>> 1. In terms of Haskell, Judy is a library of _mutable_ collections of
>> _unboxed_ elements. i pointed you to the Array wiki page, where
>> differences between boxed and unboxed, mutable and immutable
>> datastructures are described

> There's no reason you can't use Judy to implement immutable collections,
> just as we use mutable arrays to implement immutable ones.

if you mean Data.Array.Base module (not Data.Array.Diff), then mutable
arrays used there only to _initialize_ immutable ones


-- 
Best regards,
 Bulatmailto:[EMAIL PROTECTED]

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: [Haskell] My summer of code project: HsJudy

2006-06-01 Thread Simon Marlow

Bulat Ziganshin wrote:


1. In terms of Haskell, Judy is a library of _mutable_ collections of
_unboxed_ elements. i pointed you to the Array wiki page, where
differences between boxed and unboxed, mutable and immutable
datastructures are described


There's no reason you can't use Judy to implement immutable collections, 
just as we use mutable arrays to implement immutable ones.


Cheers,
Simon
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] sum-file shootout test

2006-06-01 Thread Bulat Ziganshin
Hello Haskell-cafe,

i have analyzed performance of various sum-file implementations (see
http://shootout.alioth.debian.org/debian/benchmark.php?test=sumcol&lang=all )

first, one-liner implementation (attached as b.hs) works about 500
seconds on my cpu. it can be made 10x faster just by using it's own
'read' procedure (c.hs). this tells us that current 'read' implementation
in GHC is VERY SLOW.

next step to make things go faster you can see at
http://shootout.alioth.debian.org/debian/benchmark.php?test=sumcol&lang=ghc&id=4
- now it's the fastest GHC entry on this test. speedup is a result of
throwing away all the lines/map/read/sum individual procedures and
writing entire algorithm over the plain stream of Chars. this allows
us to omit all the construction/deconstruction of lazy boxes, so this
program works about 10 seconds on my box.

now the main problem is getContents itself, which uses about 70% of
total time, because it requires to construct/deconstruct lazy box for
each Char read. Using Streams library, we can omit this work and use
straightforward imperative code (h.hs). this program works 4 times
faster (2.8 seconds) than faster Haskell variant, what should be about
1.5 times faster than today's fastest (D Digital Mars) entry in this
test

i think that close speed can be also obtained by using line-oriented
I/O in Streams+ByteString combination and then applying some
"readInt :: ByteString -> Int" conversion while compiling under GHC 6.5


-- 
Best regards,
 Bulat  mailto:[EMAIL PROTECTED]

b.hs
Description: Binary data


c.hs
Description: Binary data


h.hs
Description: Binary data
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Filtering on data constructors with TH

2006-06-01 Thread Bulat Ziganshin
Hello Christophe,

Thursday, June 1, 2006, 6:59:56 AM, you wrote:

> data Plop a b = Foo a | Bar b deriving Show
>   print $ filter isFoo l2

btw, DrIFT already have modules what implements this, along with
many other. it's a list of basic rules included in DrIFT:

standardRules = [("test",dattest, "Utility", "output raw data for testing", 
Nothing),
  ("update",updatefn, "Utility","for label 'foo' provides 
'foo_u' to update it and foo_s to set it", Nothing ),
  ("is",isfn, "Utility", "provides isFoo for each constructor", 
Nothing),
  ("get",getfn, "Utility", "for label 'foo' provide foo_g to 
get it", Nothing),
  ("from",fromfn, "Utility", "provides fromFoo for each 
constructor", Nothing),
  ("has",hasfn, "Utility", "hasfoo for record types", Nothing),
  ("un",unfn, "Utility", "provides unFoo for unary 
constructors", Nothing),
  ("NFData",nffn, "General","provides 'rnf' to reduce to normal 
form (deepSeq)", Nothing ),
  ("Eq",eqfn, "Prelude","", Nothing),
  ("Ord",ordfn, "Prelude", "", Nothing),
  ("Enum",enumfn, "Prelude", "", Nothing),
  ("Show",showfn, "Prelude", "", Nothing),
  ("Read",readfn, "Prelude", "", Nothing),
  ("Bounded",boundedfn, "Prelude", "", Nothing)]




-- 
Best regards,
 Bulatmailto:[EMAIL PROTECTED]

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: Editors for Haskell

2006-06-01 Thread Brian Hulley

Thomas Hallgren wrote:

Brian Hulley wrote:



Another thing which causes difficulty is the use of qualified
operators, and the fact that the qualification syntax is in the
context free grammar instead of being kept in the lexical syntax
(where I think it belongs).


You are in luck, because according to the Haskell 98 Report, qualified
names are in the lexical syntax!

http://www.haskell.org/onlinereport/syntax-iso.html

So, C.f is a qualified name, but C . f is composition of the
Constructor C with the function f.


Thanks for pointing this out. Although there is still a problem with the 
fact that var, qvar, qcon etc is in the context free syntax instead of the 
lexical syntax so you could write:


   2 `plus  ` 4
   (Prelude.+
  {- a comment -} ) 5 6

I think this must have been what was in the back of my mind. To make parsing 
operator expressions simple (ie LL1), it is necessary to somehow treat ` 
plus` as a single lexeme, but by having such a thing in the CFG instead 
of the lexical grammar, a "lexeme" can then occuply multiple lines (which 
means you can't associate each line with a list of lexemes for incremental 
parsing)...
Allowing "lexemes" to contain spaces and comments also makes fontification a 
bit more tricky.
Also, I can't see any sense in making such things part of the CFG instead of 
just keeping them lexical - whoever would want to put spaces in a var, qcon 
etc?
I suppose it's not an impossible problem to solve but it just makes life a 
lot harder for no good purpose that I can see.


Best regards, Brian.


--
Logic empowers us and Love gives us purpose.
Yet still phantoms restless for eras long past,
congealed in the present in unthought forms,
strive mightily unseen to destroy us.

http://www.metamilk.com 


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe