#ifdef considered harmful (was: DData)

Daan Leijen daanleijen at xs4all.nl
Thu Apr 15 13:31:52 EDT 2004

On Thu, 15 Apr 2004 11:13:34 +0100, Simon Marlow <simonmar at microsoft.com> wrote:

> Robert Will writes:
>> I think what Haskellers (and others) can do in most cases is
>> to factor out platform dependent parts to mini-modules which have different
>> implementations but the same interface.  The version of such
>> a module is choosen by the path it resides in during the build process.  (Simplest
>> case: the -i option of the compiler.)

I agree with you that in general we should avoid a preprocessor.
However, in the DData case it is hard to see a different solution.
Using a "mini module" to do the bit-fiddling won't work that well since

1) It is imperative for performance that the ghc "shiftRL#" gets inlined,
   which doesn't happen if it is in a separate module.
2) As part of the standard libraries, you can't have three extra modules for
   each system

I don't say that I *like* to use cpp here, but it is surely the easiest
solution here -- not perfect, but the perfect solution would take an
inappropiate amount of resources.

All the best,

More information about the Libraries mailing list