[Grace-core] Fwd: [important] Traits

Marco Servetto marco.servetto at gmail.com
Mon Mar 11 21:27:48 PDT 2013


I would like to discuss this proposal much more.
In particular, how much this is "defined" or "to be understood" as flattening?

some detail stuff

1)this code
def catFactory = object { method cat(name) { return object Cat(name) } }
remember me this (more) Java code:
def catFactory = new { method cat(name) { return new Cat(name) } }
And, even in this pseudo Java syntax you can add new definitions, as in
def catFactory = new { method cat(name) { return new Cat(name){....} } }
wrote in this grace proposal as
def catFactory = object { method cat(name) { return object{ inherits
Cat(name) ....}   } }

2) trait "expressions" as methods:
>>but: * we will need exactly the same static constraints from factory methods
>>    * remember traits can't themselves be objects and you can't inherit from objects.
I really think we can have a predefined class "Trait" that can answer
the messages for traits composition operators.
This will make everything very smooth, in my opinion.
Then the type system will check that the expression after the
"inherit" (or better "use") keyword returns a trait.
And in a "dynamic" setting, well we will have a dynamic error, as in
object{ inherits 1+2 .... }

Marco!


More information about the Grace-core mailing list