<div dir="ltr"><div><div><div>Hi Alex <br></div>I am no expert but try to profile your code and see the memory usage. It seems like the  sum function is causing the stack overflow[1]. <br></div>Try this one. <br>import qualified Data.ByteString.Lazy.Char8 as BS<br>
import Data.Maybe ( fromJust )<br>import Data.List <br><br>readI :: BS.ByteString -&gt; Integer<br>readI = fst . fromJust . BS.readInteger <br><br>main = BS.interact $ sumFile   where<br>     sumFile =  BS.pack . show . sum&#39; . map readI . BS.words <br>
     sum&#39; = foldl&#39; (+) 0<br><br></div>-Mukesh<br><div><div><br>[1] <a href="http://www.haskell.org/haskellwiki/Memory_leak">http://www.haskell.org/haskellwiki/Memory_leak</a><br></div></div></div><div class="gmail_extra">
<br><br><div class="gmail_quote">On Sat, Mar 23, 2013 at 8:59 PM, Axel Wegen <span dir="ltr">&lt;<a href="mailto:axel.wegen@gmail.com" target="_blank">axel.wegen@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="im">mukesh tiwari &lt;<a href="mailto:mukeshtiwari.iiitm@gmail.com">mukeshtiwari.iiitm@gmail.com</a>&gt; writes:<br>
&gt; It&#39;s already mentioned there &quot;A String is represented as a list of<br>
&gt; Char values; each element of a list is allocated individually, and has<br>
&gt; some book-keeping overhead. These factors affect the memory<br>
&gt; consumption and performance of a program that must read or write text<br>
&gt; or binary data. On simple benchmarks like this, even programs written<br>
&gt; in interpreted languages such as Python can outperform Haskell code<br>
&gt; that uses String by an order of magnitude&quot;.<br>
<br>
</div>I assumed that just means using plain Strings for that job will take<br>
more time.<br>
<div class="im"><br>
&gt; import qualified Data.ByteString.Lazy.Char8 as BS<br>
&gt; import Data.Maybe ( fromJust )<br>
&gt;<br>
&gt; readI :: BS.ByteString -&gt; Integer<br>
&gt; readI = fst . fromJust . BS.readInteger<br>
&gt;<br>
&gt; main = BS.interact sumFile where<br>
&gt; sumFile = BS.pack . show . sum . map readI . BS.words<br>
<br>
</div>I get the same result, the stack overflow. Though I don&#39;t have wait as<br>
long for it to break.<br>
<br>
I think that there is something about the summation that makes it<br>
impossible for the compiler to do it&#39;s magic and optimize the thing to<br>
something less stack overflowing. I just don&#39;t understand what that is.<br>
<br>
--<br>
Axel Wegen<br>
<div class="HOEnZb"><div class="h5"><br>
_______________________________________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org">Beginners@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/beginners" target="_blank">http://www.haskell.org/mailman/listinfo/beginners</a><br>
</div></div></blockquote></div><br></div>