[Haskell-cafe] maybe IO doesn't suck, but my code does...

Frédéric Gobry frederic.gobry at epfl.ch
Sat Dec 4 16:18:38 EST 2004

> how I think one should program in Haskell. However I have changed it to the 
> style I would recomment and now it runs in constant space.

I'm certainly interested in general remarks about style. Consider this a
my first program in Haskell, coming from object / imperative background.

> First of all I thought it is enough to strictify the members of your 
> records. Btw. this nearly never hurts if you have some kind of State 
> transition.
> >data Stat = Stat { latest :: !CalendarTime, total :: !Int } deriving (Show)

I won't forget that :-)

> Since Haskell is lazy it won't evaluate the (+) so in it keeps all copies 
> of the Stat until the very end when you actually print it. The ! annotation 
> in the record definition doesn't allow Haskell to store closures in the 
> members, so it is forced to evaluate it.

Wouldn't it be conceivable to reduce some expressions when the runtime
system notices it starts to grow too much (some sort of expression garbage
collection), or would this alter the semantic of the code too deeply ?

> Please do not use IORefs if you don't really need them. The streaming that 
> you have done by reading line by line by hand can be performed using lazy 
> IO.

You know, I started with a lines $ readFile, the code I sent is the
result of many failed attempts to overcome my problems :-)

> Recently there have been same discussion about blockwise IO and similar 
> stuff, but if you don't care to much about speed you can go with the 
> standard library.

I'll maybe perform the actual processing I need to get the job done
first, and come back to the mailing list once I'll be stuck with
blockwise IO :-)

Thanks for your help,


Frédéric Gobry    Infoscience
                  DIT-KIS / EPFL
                  Tel: +41216932288

More information about the Haskell-Cafe mailing list