It's not too hard to make this work, but it can be a bit fiddly to come up with the correct constructs. The easier one is to exclude code from the CPP, which can be easily accomplished with #if 0:
{-
#if 0
-}
cppOff = True
{-
#endif
-}
If the CPP is on, the closing comment and the cppOff definition will be ignored. The other direction, having code only available when CPP is on, requires the nested comments available in Haskell:
{-
#if 0
{-
#endif
-}
cppOn = 1
{-
#if 0
-}
#endif
-}
The non-cpp contains an extra open comment, which nests the comments, and leaves the definition invisible.
With these two fragments, you can customise your Haskell code so that it performs differently on systems with and without a CPP, remaining valid Haskell on sytems with no knowledge of CPP.
No comments:
Post a Comment