Use of cpp

Alastair Reid alastair at reid-consulting-uk.ltd.uk
Tue Jul 13 09:37:21 EDT 2004


> Unfortunately, I've broken portability by doing this and was considering
> some cpp magic to restore portability. But IIRC, the use of cpp is
> discouraged for Haskell library infrastructure.

Using cpp is preferred to breaking portability.
cpp doesn't cause any problem for Hugs (nog NHC, I think).

> Is that so? If so, what should I use instead?
> Is cpphs the way to go?

cpphs aims to be compatible with cpp up to the point where cpp starts doing 
C-specific things like string splicing, interpreting ' as the start of a 
character (and whining if the "character" doesn't end), etc.  So if your code 
works with cpp, it ought to work with cpphs.  In particular, code like the 
following should work fine.

#if GHC
#define FastInt Int#
#define plusInt(x,y) ((x)+#(y))
#else
#define FastInt Int
#define plusInt(x,y) ((x)+(y))
#endif


[In practice, I'd leave plusInt curried - I just needed an example of a macro 
with arguments.]

--
Alastair Reid


More information about the Libraries mailing list