Oh right. Thanks for pointing out. :)<br><br><div class="gmail_quote">On Wed, Aug 5, 2009 at 10:06 AM, Don Stewart <span dir="ltr">&lt;<a href="mailto:dons@galois.com">dons@galois.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
haskellmail:<br>
<div class="im">&gt; Hi all,<br>
&gt;<br>
&gt; I&#39;ve recently came across a problem when processing a large text file (around<br>
&gt; 2G in size).<br>
&gt;<br>
&gt; I wrote a Haskell program to count the number of lines in the file.<br>
&gt;<br>
&gt;<br>
&gt; module Main where<br>
&gt;<br>
&gt; import System<br>
&gt; import qualified Data.ByteString.Char8 as S<br>
&gt; -- import Prelude as S<br>
&gt;<br>
&gt; main :: IO ()<br>
&gt; main = do { args &lt;- getArgs<br>
&gt;           ; case args of<br>
&gt;               { [ filename ] -&gt;<br>
&gt;                     do { content &lt;- S.readFile filename<br>
&gt;                        ; let lns = S.lines content<br>
&gt;                        ; putStrLn (show $ length lns)<br>
&gt;                        }<br>
&gt;               ; _ -&gt; error &quot;Usage : Wc &lt;file&gt;&quot;<br>
&gt;               }<br>
&gt;           }<br>
&gt;<br>
&gt;<br>
&gt; I get this error, if I use the ByteString module,<br>
&gt; ./Wc a.out<br>
&gt; Wc: {handle: a.out}: hGetBuf: invalid argument (illegal buffer size<br>
&gt; (-1909953139))<br>
&gt; Otherwise, it returns me the result.<br>
&gt;<br>
&gt; Another observation is that if I reduce the size of the file, the ByteString<br>
&gt; version works too.<br>
&gt;<br>
&gt; Is it a known limitation?<br>
&gt;<br>
<br>
</div>Yes, you need to use Data.ByteString.Lazy.Char8 to process files larger<br>
than this on a 32 bit machine (you&#39;ll have more space on a 64 bit<br>
machine).<br>
<font color="#888888"><br>
-- Don<br>
</font></blockquote></div><br>