Hi all,<br><br>I&#39;ve recently came across a problem when processing a large text file (around 2G in size).<br><br>I wrote a Haskell program to count the number of lines in the file.<br><br><br>module Main where<br><br>import System<br>
import qualified Data.ByteString.Char8 as S<br>-- import Prelude as S<br><br>main :: IO ()<br>main = do { args &lt;- getArgs<br>          ; case args of<br>              { [ filename ] -&gt; <br>                    do { content &lt;- S.readFile filename<br>
                       ; let lns = S.lines content<br>                       ; putStrLn (show $ length lns)<br>                       }<br>              ; _ -&gt; error &quot;Usage : Wc &lt;file&gt;&quot;<br>              }<br>
          }<br>                    <br><br>I get this error, if I use the ByteString module,<br>./Wc a.out<br>Wc: {handle: a.out}: hGetBuf: invalid argument (illegal buffer size (-1909953139))<br>Otherwise, it returns me the result.<br>
<br>Another observation is that if I reduce the size of the file, the ByteString version works too.<br><br>Is it a known limitation?<br><br>Regards,<br>Kenny<br><br><br>A generator program that generate large file. (Warning, it is very slow, I don&#39;t know how to speed it up)<br>
<br>-- generate a file<br><br>module Main where<br><br>import System<br>import qualified Data.ByteString.Char8 as S<br><br><br>l :: S.ByteString<br>l = S.pack &quot;All work, no fun, make Kenny a dull boy. &quot;<br><br>main :: IO ()<br>
main = do { args &lt;- getArgs<br>          ; case args of<br>              { [ n, fn ] -&gt; do { let i = read n<br>                                ; mapM_ (\s -&gt; S.appendFile fn s) (take i $ repeat l) <br>                                }<br>
              ; _ -&gt; return () <br>              }<br>          }<br><br><br><br>