Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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) ...
    
like image 633
Zelphir Kaltstahl Avatar asked Jan 06 '23 16:01

Zelphir Kaltstahl


1 Answers

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.

like image 104
Zeta Avatar answered Jan 15 '23 12:01

Zeta