考虑以下程序.它永远运行并没有任何用处,但ghci中的内存消耗是不变的:
--NoExplode.hs
module Main (main) where
test :: [Int] -> IO()
test lst = do
print "test"
rList lst
rList :: [Int] -> IO ()
rList [] = return ()
rList (x:xs) = do
rList xs
main = do
test [1..]
Run Code Online (Sandbox Code Playgroud)
现在考虑以上的以下简单修改版本.当这个程序在ghci中运行时,内存会爆炸.唯一的区别是print "test"现在分配给x了do块test.
--Explode.hs
module Main (main) where
test :: [Int] -> IO()
test lst = do
x <- print "test"
rList lst
rList :: [Int] -> IO ()
rList [] = …Run Code Online (Sandbox Code Playgroud)