[Haskell-beginners] A first try

Antoine Latter aslatter at gmail.com
Sat Jun 25 02:51:58 CEST 2011


On Fri, Jun 24, 2011 at 11:51 PM, Jared Hance <jaredhance at gmail.com> wrote:
>
>> Lines 25-31
>> dispatch (fl, fn) = do
>>   handle <- openFile fl ReadMode
>>   contents <- hGetContents handle
>>   let cnt = getCounter fn
>>       res = cnt contents
>>   hClose handle
>>   return res
>
> Cleaner is:
>
> dispatch (fl, fn) = do contents <- withFile fl ReadMode hGetContents
>                       return $ getCounter fn contents
>

I had thought hGetContents was lazy IO. If so, will that even work?
The handle to the file will be closed before much of the file is even
read.

Antoine



More information about the Beginners mailing list