[Grace-core] Fwd: [important] Traits
Timothy Jones
tim at zimothy.com
Mon Mar 11 22:27:58 PDT 2013
> I don't remember that proposal
It was back in the dialect discussion. The main difference was that I
also suggested we should have object delegation, and have constructors
be a different case from that. James was the only one who responded, and
mentioned that constructors were basically classes with the factory
object. So I guess we've come full circle from there.
> Object
> constructors would be shorthands for classes (not the other way around)
This is what my constructors proposed as well. Object literals were
actually just instantiating singleton pseudo-classes. I don't think
there's any way to avoid this if we move to this system, because you can
always express objects in terms of instantiating a definition.
However, I like the use of the object keyword in any instantation case.
It distinguishes the two cases: here's a definition, here's an object
instantiation.
> the real question is how first-class are classes/trait expressions?
>
> I increasingly think there are only two sensible options - "not at all" and "completely"
> (presumably with "completely" watered down with some kind of static constraint...)
I really want to have a discussion about this but I don't want to clog
this email up.
>> Why not both?
>>
>> def true = object {
>> trait clone { ... }
>> }
> ?
Why can't I write this:
def true = object {
... // Rest of definition in here
trait clone is public {
... // Definition of a clone in here.
}
}
Though I imagine it would have to be defined like this (which I guess
practically results in the same code you said anyway, separating the
object instantiation from its definition):
trait newTrue {
...
trait clone is public = newTrue
}
def true = object newTrue
That said, the 'clone' trait could be built into every object if you
wanted object inheritance across the board (though I'm not suggesting this).
(I actually still want modules to just be traits, and import declaration
instantiates them. I maintain my stance that separate imports should
produce different instances of the modules).
-- Tim
More information about the Grace-core
mailing list