After a long while dealing with other languages, I wanted to refresh my aging Haskell skills a little with some codegolf inspired computation (which is intended to be lengthy). In the code below, I relied on lazy computation - but instead of a result, the machine ran out of memory...
import Data.Word
kernel :: (Word32,Word32) -> Word32
kernel (i,j) = div (i*j) 3
result :: Word32
result = sum (fmap kernel
[(i,j) |
i <- [0 :: Word32 .. 10000],
j <- [0 :: Word32 .. 10000]])
So my questions are:
- Is the list comprehension here not supposed to be lazy and then lazily provide data to
fmap
and eventuallysum
? - How else would I do it idiomatically? (I know, I could do a tail recursion implementation but that appears a bit too low level here).