Interface Implementation

extend attaches methods to a type, optionally satisfying one or more interfaces.

struct Circle {
    radius: float64;
}

extend Circle {
    func Area(self) -> float64 {
        return Pi * self.radius * self.radius;
    }
}

extend Circle: Display {
    func ToString(self) -> String {
        return Format("Circle: radius = {}", self.radius);
    }
}

The compiler verifies that the extend block provides every method the interface declares, with matching signatures. A type may satisfy any number of interfaces.

Once implemented, interface methods are called like any other method:

let c = Circle { radius: 2.0 };
Print(c.ToString());  // Circle: radius = 2

See Also