#ifdef considered harmful (was: DData)

Jan-Willem Maessen - Sun Labs East Janwillem.Maessen at Sun.COM
Thu Apr 15 10:51:18 EDT 2004

Daan Leijen wrote:
> 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.

Hmm, wouldn't it be nice to have a "FastInt" library which re-bound 
the appropriate types and functions?  Haskell libraries are 
chock-a-block with instances of "#ifdef __GHC__" which define things 
in terms of Int# instead of Int.  We could simplify all those 
libraries if we did it just once, in one place.

The problem, of course, is that the naive non-GHC user could write a 
library which used "FastInt" polymorphically, and write code that 
wasn't portable to GHC.  I don't think there's an easy, magic solution 
there.  Perhaps such a library would be named 

-Jan-Willem Maessen

> All the best,
>  Daan.
> _______________________________________________
> Libraries mailing list
> Libraries at haskell.org
> http://www.haskell.org/mailman/listinfo/libraries

More information about the Libraries mailing list