相关疑难解决方法(0)

IO/Monadic assign运算符导致ghci爆炸无限列表

考虑以下程序.它永远运行并没有任何用处,但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"现在分配给xdotest.

--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)

haskell memory-leaks ghci

17
推荐指数
1
解决办法
335
查看次数

标签 统计

ghci ×1

haskell ×1

memory-leaks ×1