
Udo Stenzel wrote:
Eugene Crosser wrote:
This is my program: ======== module Main where import Data.Map main = printMax . (foldr processLine empty) . lines =<< getContents processLine line map = insertWith (\new old -> new + old) line 1 map printMax map = putStrLn $ show $ foldWithKey (\key val accum -> if val > (snd accum) then (key,val) else accum) ("",0) map ========
You have to force the evaluation of intermediate results. To do so, you have to replace foldr by foldl (foldr is just recursion, foldl is accumulator recursion),
Having read "Yet another Haskell tutorial" (note on p.20), doesn't foldl have to read the complete list before it can start processing it (beginning from the last element)? As opposed to foldr that can fetch elements one by one as they are needed? Otherwise, point on strictness taken... Well, apparently the whole deal is even more weird than it happened at the first glance... Eugene