[Grace-core] Fwd: [important] Traits

Marco Servetto marco.servetto at gmail.com
Tue Mar 12 15:34:11 PDT 2013


> and if I want that constructor to do something else, then I have to do two things:
> (1) Write the factory method that does the two things, e.g.
>         method interval.from(base)to(limit)by(increment) {
>                 if (increment=0) then { return error "interval with 0 increment" }
>                 if (increment>0) then { object intervalUp(base,limit,increment) }
>                                         else { object intervalDown(base,limit,increment) }
> (2) change every occurrence of object interval(base,limit,increment) in the client code to
>interval.from(base)to(limit)by(increment).

Not In my mind... I expected the corresponding trait declaration to be
wrote in the following manner in the first place:
         method interval.from(base)to(limit)by(increment) {
                 if (increment=0) then { return error "interval with 0
increment" }
                 if (increment>0) then { intervalUp(base,limit,increment) }
                                         else {
intervalDown(base,limit,increment) }
and then, I create objects with
  object interval.from(...)to(...)by(...)


> One thing that I don't like at all in our current proposal is that a client can make an object by saying
>         object trait-expresssion
That is something that I do not like too, but all the ideas that I
have about avoiding it
required a nominal type system and a class-first approach, so i'm
omitting to propose those solutions for grace.
>


More information about the Grace-core mailing list