[Grace-core] Type declarations in Grace

James Noble kjx at ecs.vuw.ac.nz
Thu Jun 9 03:12:59 PDT 2011


> Type declarations of the form
>             type Pt{ … }
> would be fine.  

OK... 

> The only reason for suggesting
>             interface Pt{…}
> was because I thought we might want to have named function/closure types.  If there is no interest in that, then stick with type.

well we still can, can't we?  e.g.

interface MyCallback {
  apply(Point, String) -> Unit 
} 

or we can parameterise it 

interface Block<A,B,R>  {
  apply(A,B) -> R 
} 

type MyCallback = Block<A,B,R>

so there's another reason for type: to make aliases.
If we have other constructors: unions, intersections,
sums, tuples etc. that would be useful too even in a
structural world where (like C's typedef) all you're
doing is declaring an alias, rather than a "real",
runtime visibile (nominal) type. Although that may
make the semantics of match/case even odder...

> Types of variables as shown through interfaces:
> 
> The look of
> x:=(v: T) -> Unit
> as a declaration is pretty ugly.

yep. but method x:=(v: T) -> Unit {blah}   is ugly too.

If we let people elide the Unit (or even say: it just *doesn't* return
a value)?  or make the return value T - is that less ugly?

x:= (T) or x:=(T) -> T ain't so bad.

> There is a precedent of writing them in terms of properties in ObjectiveC (which picks up its OO syntax from Smalltalk).  Properties can be either readonly or readwrite.

Sure.   I bet there is some interaction here versus
lisp-1 vs lisp-2 choice, and also for protection.
readonly != const, for example!

> understanding the issues with the change in capitalization.  I could also live with the year:= form if necessary, but it does make me cringe a bit.

sure.  But for me at least, I think we need *one* syntax for this consistently across the whole language.
If we go to lisp-2 or lisp-1.5 like C#, we can auto-generate accessor like Eclipse,   
If we want to change it, we can change it, but we have to change it everywhere.

> (Again, keep in mind we are selling dogfood.  If instructors cringe that may be a problem even if students accept it!)
> As a second choice, I’d prefer the setYear syntax, i.e.,   o.setYear(Number) -> Unit

well right. when we tried in the blog, people (well Gilad at least) howled at the set-x version and said just call it
"x:=:".  I didn't get any particular feedback about this in my PLD/WG or MSR talks - that doesn't mean people 
like or accept it, just that they didn't complain about it.

if you went with that, how do you set locals & other lexical variables?  Also setYear? or do they use :=?

Here's another option - based on the observation that the least likely case is exposing only the setter method.

for a getter / readonly,  writing  x : T  or   x -> T seems fine.. we should pick just one of course.
I prefer x -> T for the declaration of a return type, with x : T e.g. being the type of a variable 
or/and possibly a type test if we have those which we don't! 

for a getter / setter pair: write  var x : T 
 so "var" here is the abbreviation for the two methods.  since they are actually two mthods
 not one var, we're not losing anything from an SE perspective - just that some people 
 won't like "var" being used in an interface, even if the semantics are completely OK.

then the very rare / nonexistent cases to expose just a setter can be x:=(v : T) -> T


Hmm.  Hermann @ Microsoft's parting comment was that we do seem to have 
lots of special things and special cases in Grace.  Perhaps I'm already too close
to the design to see the warts for the "clever design ideas"

argh. writing this on the plane home. probably jetlagged, if I'm coming
across too negative that's (mostly) why. 

James
 



More information about the Grace-core mailing list