[Haskell-cafe] Lazy problem ?

zaxis z_axis at 163.com
Fri Oct 23 03:15:01 EDT 2009


"ssqHitNum.txt" contains data as below:
6 7 18 24 30 32 9
4 12 20 25 28 29 16
3 5 11 12 31 32 11
2 9 13 15 19 24 3
5 17 21 25 27 32 14
5 9 15 21 26 31 13
12 16 25 26 27 31 05
...

good_ssq_red:: IO [Int]
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;
    })

statis :: [Int] -> [Int]
statis samp = take 16 $ map (\(a,b) -> a) $ sortBy (\a b-> if (snd a >= snd
b) then LT else GT) $ times4n
    where
        times =  map (\n -> (foldl (\acc x -> if x==n then acc+1 else acc) 0
samp)) [1..33]
        times4n = map (\n -> (n,times!!(n-1))) [1..33]

Does it mean that the sampe will not be evalued with `print samp` line ?  

thanks!
-- 
View this message in context: http://www.nabble.com/Lazy-problem---tp26021845p26021845.html
Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.



More information about the Haskell-Cafe mailing list