<div dir="ltr">In the following program, the function "test1" results in huge memory usage, but substituting "test2", which does essentially the same thing, does not.  GHC 7.10.1, AMD64.  Is there a different implementation of replicateM that avoids the space leak?<br><div><br>module Main where {<br>import Control.Monad;<br><br>numbers :: [Int];<br>numbers=[1..200];<br><br>-- has a space leak<br>test1 :: [[Int]];<br>test1 = replicateM 4 numbers;<br><br>-- no space leak<br>test2 :: [[Int]];<br>test2 = do {<br>x1 <- numbers;<br>x2 <- numbers;<br>x3 <- numbers;<br>x4 <- numbers;<br>return [x1,x2,x3,x4];<br>};<br><br>main :: IO();<br>main = print $ length $ test1;<br><br>}<br><br></div><div>Thanks,<br></div><div>--ken<br></div></div>