Lennart writes:

> I would have prefered to keep free type variables
> existentially in data declarations.  But I could find no nice way
> to have both universal and existential type variables so I let
> Mark Jones persuade me into this syntax.
> Existential tyvars are written with a ?, e.g.
> 
>         data Ex = MkEx ?a (?a -> Int)
> 
> Not pretty, but it's only an experimental feature anyway.
[I changed the second Ex in the above to MkEx, for clarity.]

Note that if a variable is existentially quantified in a declaration,
then it is universally quantified in the constructor.  Thus, for the
declaration above, we have

        MkEx :: a -> (a -> Int) -> Ex

This suggests it may be more sensible for existential quantification
to be the default.

By the way, this is precisely what we do in Pizza.
Here is the list type, with a universally quantified function.

        class List<a> {
          case Nil;
          case Cons(a x, List<a> xs);
          public <b> List<b> map ((a)->b f) {
            switch (this) {
              Nil: return Nil;
              Cons(a x, List<a> xs): return Cons(f(x), xs.map(f));
            }
          }
        }

Here is the existential type, defined above.

        class Ex {
          case <a> MkEx(a x, (a)->int f);
          public int eval() {
            switch (this) {
              case <a> MkEx(a x, (a)->int f): return f(x);
            }
          }
        }
                
For more on Pizza, see
        http://cm.bell-labs.com/cm/cs/who/wadler/pizza/welcome.html

Cheers,  -- P



Reply via email to