37 lines
1.1 KiB
Plaintext
37 lines
1.1 KiB
Plaintext
struct PointC(int x, int y) : Point { }
|
|
struct ColorC(int r, int g, int b) : Color { }
|
|
|
|
// Make extends clause look more like the first part of a class/struct,
|
|
// where the "with" args come in the same place as the init slots normally.
|
|
|
|
struct Point3DC(int z) : Point3D extends PointC() : Point { super(); }
|
|
|
|
type ColorPoint <: Point { Color c; }
|
|
type MovingPoint <: Point { void movePoint(int, int); }
|
|
|
|
// Make mixins look more like functions for classes to classes by
|
|
// making their "type" look more like the following:
|
|
//
|
|
// <input class type>(<with args>) -> <output class type>
|
|
|
|
mixin addColor(Color c) : Point() -> ColorPoint impl ColorPoint {
|
|
super();
|
|
export ColorPoint : x, y, c;
|
|
}
|
|
mixin makeMobile() : Point() -> MovingPoint impl MovingPoint {
|
|
super();
|
|
void movePoint(int dx, int dy) {
|
|
x = x + dx;
|
|
y = y + dy;
|
|
}
|
|
export MovingPoint : x, y, movePoint;
|
|
}
|
|
|
|
class ColorPointC = addColor(PointC);
|
|
class MovingPointC = makeMobile(PointC);
|
|
|
|
// only useable as a MovingPoint
|
|
class MovingColorPointC = makeMobile(ColorPointC);
|
|
// only usable as a ColorPoint
|
|
class ColorMovingPointC = addColor(MovingPointC);
|