
On Tue, 2004-04-06 at 12:05, Wolfgang Jeltsch wrote:
Look at XML. You are able to include XML code from other files but the code you import must be a complete XML element. Similarily, the brances of a Haskell #ifdef should be producable out of a non-terminal, and, more specific, they should be producable out of the same non-terminal. With these restrictions, one would be able to guarantee syntactical correctness without evaluating the #ifdef conditions, for example.
This doesn't work for one possible (and, I expect, common) use of a preprocessor -- if one of the branches is syntactically incorrect for some compilers. For instance, perhaps one branch uses the GHC unboxed values extensions for performance, and the other branch uses H98 for portability. I think that the best approach for dealing with the current libraries (and the issues of using them under Windows, where you might not have a convenient CPP) is the same approach others are advocating -- implement a CPP-compatible preprocessor in Haskell, and ship it with the various systems. On the other hand, if you want to design a new preprocessor that works better with Haskell, I highly recommend reading Keith Wansbrough's unpublished paper, Macros and Preprocessing in Haskell (available from http://www.cl.cam.ac.uk/users/kw217/research/paper-abstracts.html). Carl Witty