Re: [Haskell-beginners] Beginners Digest, Vol 100, Issue 20

That's not generally true (but I will give my guess about your assumption after this). See the example in the article I linked:
```
import Data.Char(toUpper)
main = do
inpStr <- readFile "input.txt"
writeFile "output.txt" (map toUpper inpStr)
```
Here, `inputStr` has to be evaluated in order to run `map toUpper` on it,
but it's done character by character. Character is read, `toUpper` is run on it, it's written to the file.
(Though it might not be a character unless we use `NoBuffering`, it's going to be lines or blocks)
Now, I guess your assumption _might_ be true in my case, because `show` might not be able to
generate the string character by character (which is very likely), in this case, show will give us the whole string in one
piece, leading to an out-of-memory error as the big string is getting loaded to memory in order to be used by `writeFile`.
This is just a guess, I would appreciate it if someone could actually prove it.
What do you think Imants?
-----Original Message-----
From: beginners-request
there should be no problem writing big strings, without consuming the whole string lazy means evaluated when needed. However when a string is evaluated, it is evaluated fully, I guess.
_______________________________________________Beginners mailing listBeginners@haskell.orghttp://mail.haskell.org/cgi-bin/mailman/listinfo/beginners

here is a very comprehensive explanation of lazy evaluation: https://github.com/takenobu-hs/lazy_evaluation I understand < 5% of this so can't add to it. about your particular problem, I would not try to rely on lazy evaluation (regardless of how it actually works) but instead break data in chunks, serialize and write the chunks to disk using libraries. This should work.
participants (2)
-
Imants Cekusins
-
Mahdi Dibaiee