jberryman
jberryman

Reputation: 16635

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.

Upvotes: 3

Views: 77

Answers (1)

Carl
Carl

Reputation: 27003

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.

Upvotes: 2

Related Questions