Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Examples

-- Marker trait.
pub trait Renewable;

-- Rule-plane contract; per-jurisdiction clauses.
pub trait Adulthood {
    derive Adult(Self)
}
impl Adulthood for USPerson     { derive Adult(p: Self) :- p.age >= 18 }
impl Adulthood for GermanPerson { derive Adult(p: Self) :- p.age >= 18, p.has_residence }

pub derive CanVote(p: Person) :-
    implements(meta(p), Adulthood), Adult(p), p.registered

-- Invocation-plane contract. The receiver leads; invocation passes
-- `self` (an individual ref) and dispatches on its actual type.
pub trait Closable {
    mutate close(self, reason: String);
}

-- Supertrait as requires-constraint (Rust's `:`). Return-position
-- `Self` is OE0675 (it would need union types / bounded generics);
-- return a concrete type.
pub trait Repaintable: Drawable {
    fn repaint_cost(self, color: Color) -> Int;
}

-- Bare impl (inherent grouping): parses per `impl Type { … }` — grouping, but its members are
-- OE1326-gated at elaboration — inherent members do not execute yet
-- (the RFD 0026 invocation plane covers trait members only).
impl Lease {
    fn extend(self, days: Nat) -> Lease;
}