Pass +RTS options to GHC’n’GHCi

For working with projects, I’m using apps from Stack. Besides, I usually also have GHCi running for quick checks. And for I didn’t really want duplicating shared libraries and file cache in RAM (i.e. the ones the system GHC is using, plus the ones that Stack does), I’m trying to stick to Stack for everything.

So to force Stack to pass RTS options to ghc and ghci you’d have to use --ghc-options and --ghci-options respectively.

I.e. I saved aliases to my ~/.zshrc (if you’re using bash, it’d be a ~/.bashrc).

alias ghci512="stack ghci --ghci-options '+RTS -M512m -RTS'"
alias ghci="stack ghci --ghci-options ''"
alias ghc="stack ghc --ghc-options ''"

Aliases won’t always work (like if you’re using a script not knowing about them), nevertheless are useful most of the time.

UPD: with aliases were problems that I fed up with, so I made up scripts instead:

$ cat /usr/bin/ghciMath512 
stack ghci --ghci-options "+RTS -M512m -RTS -ghci-script /home/constantine/.ghciMath `echo $@`"
$ cat /usr/bin/ghci       
stack ghci --ghci-options "`echo $@`"

Note the echo — it’s needed to collapse multiple arguments into a single with space-separated words.

Leave a Reply (Markdown is supported)

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s