[Haskell-cafe] Re: Why so slow?

2006-12-11 Thread apfelmus
Lyle Kopnicky wrote:
 The code below is using way more RAM than it should. It seems to only
 take so long when I build the 'programs' list - the actual
 reading/parsing is fast. For a 5MB input file, it's using 50MB of RAM!
 Any idea how to combat this?

(ethereal voice)
... Children of Amaunator ... heed my words ... in no long, the world
... will perish, will ... crumble under the blackened forces of IO ...
but there is ... hope ... i can feel that ...
ensure :: (a - Bool) - String - a - a
ensure b s x = if b x then x else error s
... or switching to ... monadic parser combinators ... like
Text.ParserCombinators.Parsec ... can hold strong the light for ...
another aeon or two ...



Regards,
afpelmus

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


[Haskell-cafe] Re: Why so slow?

2006-12-11 Thread Benjamin Franksen
Lyle Kopnicky wrote:
 The code below is using way more RAM than it should. It seems to only
 take so long when I build the 'programs' list - the actual
 reading/parsing is fast. For a 5MB input file, it's using 50MB of RAM!
 Any idea how to combat this?

1) I strongly recommend to work through at least the relevant parts of the
tutorial 'Write yourself a scheme in 48 hours' (google for the title). It
explains how to use efficient parser combinator libraries, how to cleanly
separate IO from pure computations, how to use Error monad (instead of IO)
to recover from errors, etc. pp.

2) Use String or ByteString.Lazy together with readFile to read the input on
demand. Else your program must suck all of the input into memory before
processing can even start. (This works whenever processing of the input
stream is more or less sequential).

HTH
Ben

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