How can I increase the stack size with runhaskell?

旧城冷巷雨未停 提交于 2019-12-23 07:27:17

问题


I'm writing some disposable Haskell scripts to solve some of the Project Euler problems. I don't really want to have to compile them because of the number of changes I'm constantly having to make, but in a few cases I've found that I've run out of stack space.

The documentation for runhaskell says that the following syntax should increase the stack space:

runhaskell +RTS -K5M -RTS Script.hs

This never, ever works (in any permutation I've tried). The stack size always remains 8,388,608. This is maddening, and I haven't found much help on Google.

Any suggestions? What am I doing wrong?


回答1:


I'm guessing you're using GHC. Chapter 4 of the User's Guide of the newly released 6.10.1 says:

The only runghc flag currently is -f /path/to/ghc, which tells runghc which GHC to use to run the program.

I don't see a bug logged at http://hackage.haskell.org/trac/ghc . Seems pretty lame to me. I'd suggest asking on irc #ghc, or the cvs-ghc mailing list.

Of the other Haskell compilers/interpreters, only nhc98 seems allow you to set the max stack size. Depending on your OS, nhc98 could be an option.




回答2:


I'm doing the same thing (Project Euler) and have been using ghc. The trick (thanks #haskell!) is to tell the executable to have more stack size rather than the compiler.

$ ghc -O2 -o 23 23.hs
$ ./23 +RTS -K128M



回答3:


Just compile it.

Problem123.hs:

module Main where
main = do
    print solution
solution = ...

Short and sweet command line:

ghc --make -O3 Problem123.hs
./Problem123

Final note: I'm not sure I would call them "scripts".



来源:https://stackoverflow.com/questions/275250/how-can-i-increase-the-stack-size-with-runhaskell

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!