[Haskell-cafe] Conditional compilation

Sittampalam, Ganesh ganesh.sittampalam at credit-suisse.com
Sat Mar 28 13:21:53 EDT 2009

Robin Green wrote:
> I am writing some code for citation support in gitit, and all the
> #ifdefs I'm using to do conditional compilation are a bit tiresome.
> Suppose you have the requirement that a certain feature of your
> software be disable-able at compile time, to avoid having to pull in
> certain dependencies (which may not be available on all platforms).
> Disabling a feature may entail removing certain fields from certain
> constructors (again, to avoid pulling in certain dependencies), and/or
> removing certain functions from certain modules. What is the best way
> to do this in Haskell?

I would parameterise over the functionality (i.e. use type parameters to
datatypes and HOF parameters to functions where appropriate), and
instantiate the types with () or some useful type as appropriate. Some
CPP would still be required but hopefully only at the top level.


 Please access the attached hyperlink for an important electronic communications disclaimer: 

More information about the Haskell-Cafe mailing list