<font color='black' size='2' face='arial'>
<div> <font size="2">That's not generally true (but I will give my guess about your assumption after this). See the example in the article I linked:<br>
<br>
```</font><br>
<pre id="toupper-lazy3.hs:all" class="programlisting">import Data.Char(toUpper)
main = do
inpStr <- readFile "input.txt"
writeFile "output.txt" (map toUpper inpStr)</pre><font size="2">```<br>
<br>
Here, `inputStr` has to be evaluated in order to run `map toUpper` on it,<br>
but it's done character by character. Character is read, `toUpper` is run on it, it's written to the file.<br>
(Though it might not be a character unless we use `NoBuffering`, it's going to be lines or blocks)<br>
<br>
Now, I guess your assumption _might_ be true in my case, because `show` might not be able to<br>
generate the string character by character (which is very likely), in this case, show will give us the whole string in one<br>
piece, leading to an out-of-memory error as the big string is getting loaded to memory in order to be used by `writeFile`.<br>
<br>
This is just a guess, I would appreciate it if someone could actually prove it.<br>
<br>
What do you think Imants?<br>
</font>
</div>
<div> <br>
</div>
<div style="font-family:arial,helvetica;font-size:10pt;color:black">-----Original Message-----<br>
From: beginners-request <beginners-request@haskell.org><br>
To: beginners <beginners@haskell.org><br>
Sent: Sat, Oct 29, 2016 3:44 pm<br>
Subject: Beginners Digest, Vol 100, Issue 20<br>
<br>
Send Beginners mailing list submissions to
<a href="mailto:beginners@haskell.org">beginners@haskell.org</a>
To subscribe or unsubscribe via the World Wide Web, visit
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners</a>
or, via email, send a message with subject or body 'help' to
beginners-<a href="mailto:request@haskell.org">request@haskell.org</a>
You can reach the person managing the list at
beginners-<a href="mailto:owner@haskell.org">owner@haskell.org</a>
When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."
Today's Topics:
1. Writing huge result of `show` to file results in out of
memory (Mahdi Dibaiee)
2. Re: Writing huge result of `show` to file results in out of
memory (Imants Cekusins)
<div id="AOLMsgPart_3.1_328fd489-f8d0-4d3e-baa5-d949e829080a" style="margin: 10px;">
<div style="font: 11px arial;border: 1px solid #7DA8D4;background: #F9F9F9;">
<div style="font: 11px arial;background: #B5DDFA;padding: 3px 3px 3px 3px;">Attached Message</div>
<table>
<tbody><tr valign="top">
<td style="font: 11px arial;color: #000000;padding: 1px 10px 1px 9px;background: #F9F9F9;" nowrap="">From</td>
<td style="font: 11px arial;color: #000000;background: #F9F9F9;">Mahdi Dibaiee <mdibaiee@aol.com></td>
</tr>
<tr valign="top">
<td style="font: 11px arial;color: #000000;padding: 1px 10px 1px 9px;background: #F9F9F9;">To</td>
<td style="font: 11px arial;color: #000000;background: #F9F9F9;">beginners@haskell.org</td>
</tr>
<tr valign="top">
<td style="font: 11px arial;color: #000000;padding: 1px 10px 1px 9px;background: #F9F9F9;">Subject</td>
<td style="font: 11px arial;color: #000000;background: #F9F9F9;">[Haskell-beginners] Writing huge result of `show` to file results
in out of memory</td>
</tr>
<tr valign="top">
<td style="font: 11px arial;color: #000000;padding: 1px 10px 1px 9px;background: #F9F9F9;">Date</td>
<td style="font: 11px arial;color: #000000;background: #F9F9F9;">Fri, 28 Oct 2016 12:57:22 -0400</td>
</tr>
</tbody></table>
</div>
<div id="AOLMsgPart_3.1.2_3419c892-6ef9-46e2-ab61-98cb53cbcfde">
<div class="aolReplacedBody"><font size="2" color="black" face="arial"><font size="2">I know that there are other ways of doing it, I just want to understand<br>
where lies the problem here.<br>
<br>
I just read the realworldhaskell book by O'Reilly, in one section, Lazy I/O [0], it's explained<br>
that there should be no problem writing big strings, without consuming the whole string<br>
to files, however big they are.<br>
<br>
I would appreciate it if someone could point out the problem there.<br>
<br>
Thanks<br>
<br>
[0]: <a href="http://book.realworldhaskell.org/read/io.html#io.lazy" target="_blank">http://book.realworldhaskell.org/read/io.html#io.lazy</a><br>
</font>
</font></div>
</div>
</div>
<!-- end of AOLMsgPart_3.1_328fd489-f8d0-4d3e-baa5-d949e829080a -->
<div id="AOLMsgPart_3.2_1bc104d8-4dcd-47ed-b4da-004f5f59b82e" style="margin: 10px;">
<div style="font: 11px arial;border: 1px solid #7DA8D4;background: #F9F9F9;">
<div style="font: 11px arial;background: #B5DDFA;padding: 3px 3px 3px 3px;">Attached Message</div>
<table>
<tbody><tr valign="top">
<td style="font: 11px arial;color: #000000;padding: 1px 10px 1px 9px;background: #F9F9F9;" nowrap="">From</td>
<td style="font: 11px arial;color: #000000;background: #F9F9F9;">Imants Cekusins <imantc@gmail.com></td>
</tr>
<tr valign="top">
<td style="font: 11px arial;color: #000000;padding: 1px 10px 1px 9px;background: #F9F9F9;">To</td>
<td style="font: 11px arial;color: #000000;background: #F9F9F9;">The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <beginners@haskell.org></td>
</tr>
<tr valign="top">
<td style="font: 11px arial;color: #000000;padding: 1px 10px 1px 9px;background: #F9F9F9;">Subject</td>
<td style="font: 11px arial;color: #000000;background: #F9F9F9;">Re: [Haskell-beginners] Writing huge result of `show` to file
results in out of memory</td>
</tr>
<tr valign="top">
<td style="font: 11px arial;color: #000000;padding: 1px 10px 1px 9px;background: #F9F9F9;">Date</td>
<td style="font: 11px arial;color: #000000;background: #F9F9F9;">Fri, 28 Oct 2016 19:13:23 +0200</td>
</tr>
</tbody></table>
</div>
<div id="AOLMsgPart_3.2.2_0de71afd-a925-48c9-84bf-f147d898fb60">
<div class="aolReplacedBody">
<div dir="ltr"><span style="color:rgb(0,0,0);font-family:arial">> there should be no problem writing big strings, without consuming the whole string</span><br>
<div>lazy means evaluated when needed. However when a string is evaluated, it is evaluated fully, I guess.<br>
</div>
</div>
</div>
</div>
</div>
<!-- end of AOLMsgPart_3.2_1bc104d8-4dcd-47ed-b4da-004f5f59b82e -->
_______________________________________________
Beginners mailing list
<a href="mailto:Beginners@haskell.org">Beginners@haskell.org</a>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners</a>
</div>
</font>