infix type constructors

Okasaki, C. DR EECS Christopher.Okasaki@usma.edu
Thu, 16 May 2002 11:04:51 -0400


Simon wrote:
> I'm slowly getting around to this.   Design questions:
> 
> (A) I think it would be a good compromise to declare that operators
> like "+" are type *constructors* not type *variables*.  So 
> 	S+T
> would be a type.  That's slightly inconsistent with value variables,
> but it's jolly useful.  So only alphabetic things would be type
> variables.
> It's very clunky having to write
> 	S :+: T

As a design principle, I would recommend keeping
type constructors and value constructors as similar
as possible.  So I would require infix type constructors
to begin with a :, just like value constructors.  Yes,
it's clunky, but no more clunky than for value constructors.

> (B) One wants to declare fixities for type constructors, and that
> gets them mixed up with their value counterparts.  My suggestion:
> disamiguate with a compulsory 'type' keyword
> 	infix 6 type +
> 	infixl 9 type *
> 
> Or should it be 'data'?  Or should it depend how + and * are declared?

My preference here would be for an infix declaration for
a given name to apply to both type and value constructors.
So, if you have a type constructor :- and a value constructor
:-, they will have exactly the same precedence and
associativity.  I think it would be far too confusing
for a type
  a :-: b :+: c
to parse differently than an expression
  x :-: y :+: z

> (C) The other place they can get mixed up is in import and export
> lists.  I can think of several solutions
> 
> (i) 	module Foo( + ) where ...
>     means export the type constructor (+); currently illegal in H98
> 	module Foo( (+) ) where ...
>    means export the variable (+).
> 
> This seems a bit of a hack.
> 
> (ii) Use the 'type' keyword, rather like 'module':
> 	module Foo( type + ) where 
> 		data a+b = A a | B b
> or
> 	module Foo( type +(A,B) ) where
> 		data a+b = A a | B b
> 
> [I think 'type' is better than 'data' because we want to hide the 
> distinction in an export list.... or do you think we should use the 
> same keyword as the one in the defn?]
> 
> Similarly on import lists.

If you keep the : prefix for infix type constructors,
then this issue doesn't arise, just as it doesn't for
alphabetic type and value constructors.

> (D) I suppose one might want infix notation for type variables too:
> 
> 	data T a = T (Int `a` Int)
> 
> but maybe that's going too far?

I don't have a strong feeling either way about this one.

-- Chris