Search code examples
haskellghccabal

Conditional compilation based on interactive (GHCi) or compiled


Is there a way to use the CPP to compile different versions of some code based on whether we're in ghci or whether the code is compiled? Alternatively, conditional compilation based on whether optimizations are on might work.


Solution

  • You could use a RULES pragma. They only fire when optimizations are on. A simple pragma replacing one binding with another would allow you to change the definition of something only when optimizations are on - though it would still require compiling both versions all the time.

    It's not a great solution - but I'm of the opinion that it's not a great thing to want to do, either.