-
Notifications
You must be signed in to change notification settings - Fork 89
Traits
Alex Zimin edited this page Jul 11, 2011
·
3 revisions
(not yet done) http://www.iam.unibe.ch/~scg/Research/Traits/
Example:
trait TCircle[T] {
require {
Radius () : int;
Rotate (x : int) : T;
}
provide {
Diameter () : int
{
Radius () * 2
}
RevRotate (x : int) : T
{
Rotate (-x)
}
}
}
This should translate to:
interface TCircle[T]
where T : TCircle[T]
{
Radius () : int;
Rotate (x : int) : T;
Diameter () : int;
RevRotate (x : int) : T;
static impl_Diameter (_this : T) : int
{
_this.Radius () * 2
}
static impl_RevRotate (_this : T, x : int) : T
{
_this.Rotate (-x)
}
}
and later:
class SomeCircle
{
uses TCircle;
public Radius () : int { 42 }
public Rotate (_ : x) : SomeCircle { this }
}
to:
class SomeCircle : TCircle[SomeCircle]
{
public Radius () : int { 42 }
public Rotate (_ : x) : SomeCircle { this }
public Diameter () : int { TCircle[SomeCircle].impl_Diameter (this) }
public RevRotate (x : int) : int {
TCircle[SomeCircle].impl_RevRotate (this, x)
}
}
Think about removing conflicts.