我已找到this question及其答案。
在accepted answer上,您可以看到我对该解决方案的评论。例如,它似乎不适用于此功能:
fiblist = 0 : 1 : (zipWith (+) fiblist (tail fiblist))
fib :: (Integral a) => a -> String
fib n
| n < 10000 = show (genericIndex fiblist n)
| otherwise = error "The number is too high and the calculation might freeze your machine."
即使我只提供GHCI 256Mb堆和256Mb堆栈空间,它仍会使系统无法使用。对于length
(无限列表)的简单调用,它确实有效。
我现在的问题是:所有案例的解决方案是什么样的? (有没有?如果没有,为什么不呢?)
编辑#1:其他信息
stack ghci +RTS -M256m -K256m
GHC版本:stack ghc -v
导致:
Version 1.0.2, Git revision fa09a980d8bb3df88b2a9193cd9bf84cc6c419b3 (3084 commits) x86_64
... (a lot of other stuff) ...
答案 0 :(得分:8)
stack ghci +RTS -M256m -K256m
那不是设置GHCi的RTS选项,而是stack
。毕竟,stack
也是在Haskell中编写的,因此也可以使用RTS选项。
使用--ghci-options
为GHCi提供其他选项:
stack ghci --ghci-options="+RTS -M256m -K256m -RTS"
结束-RTS
是必要的,因为stack
为GHCi提供了更多选项。
答案 1 :(得分:1)
您的问题出在调用中。
stack ghci +RTS -M256m -K256m
Stack不会将这些参数传递给ghci:
/.../.stack/programs/x86_64-osx/ghc-7.10.2/lib/ghc-7.10.2/bin/ghc -B/.../.stack/programs/x86_64-osx/ghc-7.10.2/lib/ghc-7.10.2 --interactive -odir=/.../.stack/global/.stack-work/odir/ -hidir=/.../.stack/global/.stack-work/odir/
如果您改为直接调用ghci:
/usr/local/lib/ghc-7.10.3/bin/ghc -B/usr/local/lib/ghc-7.10.3 --interactive +RTS -M256m -K256m
耶!参数!
我怀疑你的+RTS ...
实际上正被堆栈自己的RTS使用 - 就像在,堆栈是用Haskell编写的,并且在你真正希望ghci遵循所述约束时遵循这些约束。所以...提交堆栈问题。