"Manuel M. T. Chakravarty" wrote:
> 
> George Russell <[EMAIL PROTECTED]> wrote,
> This sounds interesting.  So you want the branch that is not
> taken to be syntactically correct, but it need not type
> check.  How about other semantic constraints (visibility of
> names etc)?  If you want to use this mechanism for selecting
> whether or not to use non-standard features, you probably
> also have to allow that the branch not taken is
> syntactically illegal (eg, use of GHC's unboxed values in
> one branch and plain Haskell in the other).  How is this
> exactly in Java?
I suspect that in Java both branches would have to be syntactically
correct, though I can't be bothered to look it up.  Hmm, I hadn't 
thought of that.  But it shouldn't be hard to think up some way
round which is prettier than the CPP version; it could hardly be
uglier!

If we are going to have a different name for "if" when it is
used in this way (and I think we should anyway) we may as well
call it #if and be like C.  This will mean that existing programs
should go through without much modification. So I suggest
(1) The compiler keeps track of which values at top level are
    "constant expressions".  A constant expression is an
    Integer, Bool or String, or something obtained thereof
    by the obvious operations (arithmetic, comparison,
    perhaps if itself, ++).  When a value bound to a constant
    expression is exported, its constant expression status
    is exported too.  
(2) the CPP conditional syntax (#if, #else, and so on)
    but NOTHING ELSE from CPP.  The argument to #if must
    be a constant expression.
(3) Where appropriate the compiler may allow values to be
    bound to constant expressions on the command line.
Yes I know it's pretty ghastly, but it's still 10000 times better
than using CPP.   And I don't think it should be too ghastly to
implement.   The main bother would that the change would have to
be agreed precisely between the Hugs and GHC folk.



Reply via email to