Zelphir Kaltstahl
Zelphir Kaltstahl

Reputation: 6189

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

Upvotes: 4

Views: 839

Answers (2)

Zeta
Zeta

Reputation: 105876

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.

Upvotes: 8

Thomas M. DuBuisson
Thomas M. DuBuisson

Reputation: 64740

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.

Upvotes: 1

Related Questions