4

I already found this question and the answers to it.

On the accepted answer you can see my comment about the solution. It doesn't seem to work for example for this function:

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."

It still renders the system unusable, even if I only give GHCI 256Mb Heap and 256Mb Stack space. For a simple call of length (of an infinite list) it does work.

My question now is: What does the solution for all cases look like? (Is there one? If not, why not?)

Edit #1: Additional information

  • OS: Xubuntu 14.04
  • RAM: 4GB
  • Exact command I used for GHCI: stack ghci +RTS -M256m -K256m
  • GHC Version: stack ghc -v results in:

    Version 1.0.2, Git revision fa09a980d8bb3df88b2a9193cd9bf84cc6c419b3 (3084 commits) x86_64
    ... (a lot of other stuff) ...
    
4

2 回答 2

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 提供了更多选择。

于 2016-02-11T17:41:13.153 回答
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 遵循所述约束时遵循这些约束。所以...提交堆栈问题。

于 2016-02-11T17:40:46.917 回答