[Haskell-cafe] A restricted subset of CPP included in a revision of Haskell 98

Brian Smith brianlsmith at gmail.com
Thu Aug 17 14:54:30 EDT 2006


On 8/17/06, John Meacham <john at repetae.net> wrote:
>
> On Thu, Aug 17, 2006 at 11:44:17AM -0500, Brian Smith wrote:
> > Hi,
> >
> > I find it strange that right now almost every Haskell program directly
> or
> > indirectly (through FPTOOLS) depends on CPP, yet there is no effort to
> > replace CPP with something better or standardize its usage in Haskell.



> see this paper for some interesting work on the subject.
> http://citeseer.ist.psu.edu/wansbrough99macros.html


Thanks for that. I should have not said "there is no effort to replace CPP"
before. I hope I did not offend anybody that has worked on this problem
previously.

I was also mistaken in saying that syntax could be fully checked without
knowing any preprocessor symbol bindings. This is only true if one gets rid
of the ability to choose between two syntaxes via the preprocessor.  But, if
we allow syntax that we can't parse (but presumably another implementation
can), then the preprocesor must remain a true preprocessor. Then there isn't
much reason to place so many restrictions on where the various preprocessor
directives may appear.

I proposed to limit where #define could appear mostly for asthetic reasons.
If #define, #error, and #warn only appear at the beginning of a file, then
the rest of the file would only contain Haskell syntax in between
#if...#else...#endif. Also, a refactoring tool would not have these
directives get in its way.

I want to have conditionals limited in their placement to make things easier
for refactoring tools. But, I don't have any ideas about how to deal with
conditional exports without allowing preprocessor conditionals in the export
list.

* #define can only be used for parameterless definitions
* #define'd symbols are only visible to the preprocessor
* #define can only give a symbol a value that is a valid preprocessor
expression
* #define, #error, and #warn can only appear above the module declaration
* a preprocessor symbol, once defined, cannot be undefined or redefined with
a different value
* #include and #undef are prohibited
* The preprocessor can only be used at the top level. In particular, a
prepropcessor conditional or #line would not be allowed within the export
list or within a top-level binding.
* A Haskell program must assume that any top-level symbol definitions are
constant over the entire program. For example, a program must not depend on
having one module compiled with one set of command-line preprocessor symbol
bindings and another module defined with a different set of bindings.
* preprocessor directives must loosely obey * #define can only be used for
parameterless definitions
* #define'd symbols are only visible to the preprocessor
* #define can only give a symbol a value that is a valid preprocessor
expression
* #define can only appear above the module declaration
* a preprocessor symbol, once defined, cannot be undefined or redefined
* #include and #undef are prohibited
* The preprocessor can only be used at the top level. In particular, a
prepropcessor conditional, #error, #warn, #line would not be allowed within
the export list or within a top-level binding.
* A Haskell program must assume that any top-level symbol definitions are
constant over the entire program. For example, a program must not depend on
having one module compiled with one set of command-line preprocessor symbol
bindings and another module defined with a different set of bindings.
* preprocessor directives must obey a very simple layout rule: an #if,
#else, or #endif cannot be indented more than the bindings it "contains."
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org//pipermail/haskell-cafe/attachments/20060817/a969a147/attachment.htm


More information about the Haskell-Cafe mailing list