Abstractions

Classes and instances

Read the class surface and define instances.

What

Classes define shared behavior names. Instances provide concrete implementations for those behavior names.

Why

This pattern keeps behavior contracts explicit and avoids repeating equivalent helper sets.

How

Define a class, then declare matching instances for concrete types.

let Eq[T] := class {
  let (=) (a : T, b : T) : Bool;
  law reflexive (x : T) := true;
};
let eqInt := instance Eq[Int] {
  let (=) (a : Int, b : Int) : Bool := true;
};

When

Use classes when you want one operation (for example equality or formatting) to work across multiple domains.

Analogy

Like interfaces in JavaScript/TypeScript, but with explicit instance attachment in the same language surface.

Try it

Review both snippets, then continue to Attributes and foreign declarations.