from micro-rant to macro-feature

Malcolm Wallace Malcolm.Wallace@cs.york.ac.uk
Fri, 10 Aug 2001 11:12:47 +0100


Gary Memovich writes:

> Now if we only expanded the flexibility of 'newtype' declarations so
> that we could include a conversion function to the underlying type,
> and expand the type checking system to automatically add calls to such
> a function when needed, and change the syntax so that the constructor
> for 'newtype' wasn't limited to identifiers, and change the syntax
> some more so that new 'prefix' declarations were available to adjust
> the precedence levels of these new constructors, it would be a piece
> of cake :-)

As a point of interest, nhc98 extends very slightly the Haskell
syntax for declaring infix and precedence to permit user-defined
prefix operators.  For instance:

    infixl 7  *
    infixl 6  +
    prefix negate 6 - 

The extended syntax is

    gendecl  ->  vars '::' [context '=>'] type
             |   fixity [digit] ops
             |   'prefix' varid [digit] op
             |

and the obvious semantics is that the unary operator is treated
as if it were really the varid.  Do feel free to play with it.
(Note however that this kind of declaration does not change the
pattern-matching language for constants - negative integer patterns
are just fiddled by the compiler.)

Regards,
    Malcolm