[Grace-core] Type declarations

Timothy Jones tim at ecs.vuw.ac.nz
Wed Mar 19 16:26:43 PDT 2014


James mentioned this in an email a few days ago, but I only just got around to
writing this up.

I've been writing a lot of type declarations, and come to the conclusion that
the use of the type keyword for both declarations and structural type literals
is weird. The special case for leaving of the keyword is also strange. I'm
proposing we use a different keyword for type literals. At the moment I'm
tentatively going with 'interface', though I'd prefer something shorter if
anyone has any ideas.

  type MutableList<E> = List<E> & interface {
    add(element : E) -> Done
    at(index : Number) put(element : E) -> Done
  }

The current system feels as though we were using 'def' as both the form for
declaring a variable and creating an object, with a special case for declaring a
def as an object directly. Using a different keyword for the structural type
literals makes it more clear what the literal represents, and avoids the
syntactic noise that comes with having 'type' on both sides of a type
declaration. I also think this is more consistent with the notion that many
patterns which aren't interface declarations can also be static types.

-- 
Tim


More information about the Grace-core mailing list