gpt4 book ai didi

Haskell,限制 GHCI 内存

转载 作者:行者123 更新时间:2023-12-02 14:34:55 27 4
gpt4 key购买 nike

我已经找到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:附加信息

  • 操作系统:Xubuntu 14.04
  • 内存:4GB
  • 我用于 GHCI 的确切命令: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) ...

最佳答案

stack ghci +RTS -M256m -K256m

这不是设置 GHCi 的 RTS 选项,而是设置堆栈。毕竟,stack 也是用 Haskell 编写的,因此也可以采用 RTS 选项。

使用 --ghci-options 为 GHCi 提供其他选项:

stack ghci --ghci-options="+RTS -M256m -K256m -RTS"

关闭-RTS是必要的,因为stack为GHCi提供了更多选项。

关于Haskell,限制 GHCI 内存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35342591/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com