[Haskell] [Haskell - I/O] Problem with 'readFile'
John Hughes
rjmh at cs.chalmers.se
Sun Aug 27 09:45:21 EDT 2006
> Hello L.,
>
> Sunday, August 27, 2006, 12:43:24 PM, you wrote:
>
>>> > length s `seq` writeFile f ("hello"++s)
>
>> length mates_str `seq` return ()
>
> it's the same. i recommend you to use:
>
> return $! tail mates_str
>
> $! defined as
>
> f$!x = x `seq` f x
>
> 'tail' should be slightly faster than 'len'
>
> --
> Best regards,
> Bulat mailto:Bulat.Ziganshin at gmail.com
But you need to evaluate the result of readFile all the way to the end--you
need to use a function that traverses the entire file contents. Otherwise
the file will be left open to read the bit you haven't traversed. Hence
length rather than tail.
John
More information about the Haskell
mailing list