简体   繁体   中英

Haskell, Limit GHCI memory

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) ... 
 stack ghci +RTS -M256m -K256m 

That's not setting the RTS options of GHCi, but stack . After all, stack is also written in Haskell and therefore can take RTS options too.

Use --ghci-options to provide additional options to GHCi instead:

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

The closing -RTS is necessary since stack provides some more options to GHCi.

Your issue is in the invocation.

stack ghci +RTS -M256m -K256m

Stack does not pass these parameters through to 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/

If you instead invoke ghci directly:

/usr/local/lib/ghc-7.10.3/bin/ghc -B/usr/local/lib/ghc-7.10.3 --interactive +RTS -M256m -K256m

Yay! Arguments!

I suspect your +RTS ... is actually being consumed by stack's own RTS - as in, stack is written in Haskell and is following these constraints when you actually desire ghci to follow said constraints. So... submit an issue for stack.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM