[Haskell-cafe] Lazy problem ?

Gregory Crosswhite gcross at phys.washington.edu
Fri Oct 23 04:39:14 EDT 2009


Or

good_ssq_red = readFile "ssqHitNum.txt" >>= return . statis . str2Ints

I personally prefer this because I like how the >>= illustrates that  
the result is being fed into "return . statis . str2Ints", but it is a  
matter of style.  :-)

Cheers,
Greg


On Oct 23, 2009, at 1:09 AM, Bulat Ziganshin wrote:

> Hello zaxis,
>
> Friday, October 23, 2009, 12:02:57 PM, you wrote:
>
> btw,
>
> good_ssq_red = fmap (statis.str2Ints) $ readFile "ssqHitNum.txt"
>
> or
>
> good_ssq_red = (statis.str2Ints) `fmap` readFile "ssqHitNum.txt"
>
>
>> good_ssq_red:: IO [Int]
>> good_ssq_red =do {
>>    samp <- fmap str2Ints $ readFile "ssqHitNum.txt";
>>    return $ statis samp;
>> }
>> It works now !  thank you
>
>
>> Bulat Ziganshin-2 wrote:
>>>
>>> Hello zaxis,
>>>
>>> Friday, October 23, 2009, 11:15:01 AM, you wrote:
>>>
>>>> good_ssq_red = withFile "ssqHitNum.txt" ReadMode (\h -> do {
>>>>        samp <- fmap str2Ints $ hGetContents h;
>>>>        print samp;    --without this line, the result will always
>>>> [1..16]
>>>>        return $ statis samp;
>>>>    })
>>>
>>> withFile and hGetContents shouldn't be used together. both closes  
>>> file
>>> handle and, here, withFile closes it before hGetContents lazily  
>>> reads
>>> data. it's why you need to force reading with print
>>>
>>> use readFile instead
>>>
>>>
>>>
>>> -- 
>>> Best regards,
>>> Bulat                            mailto:Bulat.Ziganshin at gmail.com
>>>
>>> _______________________________________________
>>> Haskell-Cafe mailing list
>>> Haskell-Cafe at haskell.org
>>> http://www.haskell.org/mailman/listinfo/haskell-cafe
>>>
>>>
>
>
>
>
> -- 
> Best regards,
> Bulat                            mailto:Bulat.Ziganshin at gmail.com
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe



More information about the Haskell-Cafe mailing list