[Grace-core] Polymorphic/generic classes, etc.

James Noble kjx at ecs.vuw.ac.nz
Thu Jun 16 03:48:37 PDT 2011


> In this e-mail I show some code using matching and then make a proposal for support for parametric polymorphism.

good...

> Our Grace implementation is making good progress.  Here is a sample program that compiles (including type-checks) and then runs correctly:


sounds good!

> Note that the match statement needed "str: SomeStringType" rather than "str: StringType" because classes can't be used as types.  

yep... this is something we do need to talk over (and perhaps get more experience with it)

but on your code - how does the structural SomeStringType differ from the type of NoneString (or OptionString)
(or are your types nominal?)

> The version using extractor function (not yet implemented) could replace that with case {SomeString(s) -> ...}" using the class rather than type, a generalization that seems useful.

Hmm - I'm not quite sure why that lets you use the class, but the other once doesn't..
There's also a question about the syntax we want to allow for patterns - do we want "function like" 
things like "SomeString(s)"?  or "message like" syntax ? <SomeString.new(s)>

I need to type up my notes from last week on this and other things! 

> I have a simple proposal (not yet implemented) for parametric polymorphism that can be illustrated by a variant of the same example.  Type parameters are enclosed in square brackets.

Ok - we have to decide about those brackets...

> Hopefully the example is pretty self-explanatory.

I just get a real kick out of seeing working Grace code! 

> We can also support F-bounded polymorphism (and polymorphic methods) as in the following example:

cool...

>        class ComparablePair[T,U] implements Comparable[T]   // builds new comparable out of a simpler one
>                          where T extends Comparable[T] {                       // Suggest writing constraint as "where" clause after "implements"

entends or implements or T <: Comparable[T]   // this way lies Scala! 

>             method map[U](f:{(T) -> U}) -> List[U] {...}         // notice how write a polymorphic method

I'm not quite sure what this means - but one the whole I like writing the
types of blocks/closures etc as (S,T)->U ..

> While I would have loved to add a MyType construct, I restrained myself (with some difficulty).
> 
> Any comments?

re MyType, I'm still not sure why you're restraining yourself.
Given that we seem close to buying into the whole gBETA / Newspeak nesting model,
MyType (or SelfType?) isn't adding that much more complexity, is it?

and then there's scope for exact types:  =T,   nullable types ?T,  ... 


this is all written in Scala, right?
I wonder how far your code that is from Grace, 
and how hard it would be to lift the checker to Grace
code working on a reified AST in Grace...

James



More information about the Grace-core mailing list