Enums with payloads

An enum is a tagged union. A unit variant carries only its identity; a payload variant carries typed positional values. Construct with Enum.Variant(...) and inspect with a pattern.

moon checks enum matches for exhaustiveness, including payload structure, and rejects arms that can never be reached.

enum Shape {
  Dot,
  Circle(float),
}

fn describe(shape: Shape) -> string {
  match shape {
    Shape.Dot => "dot",
    Shape.Circle(radius) => "circle $radius",
  }
}

fn main() { println(describe(Shape.Circle(2.5))) }
Output & diagnostics
Expected:
circle 2.5
Ctrl/⌘+Enter runs the current lesson.