Examples

Unions

Named variants with payloads, and a when that must cover them all.

main (print)

# A union is one of several named variants, each with its own payload.
<shape: circle float | square float | empty none>

area(s &shape) float
    when s is
        <shape: circle> 3.14159 * circle * circle
        <shape: square as side> side * side
        <shape: empty> 0.0

main()
    shapes = [shape: <shape: circle = 1.0>, <shape: square = 2.0>, <shape: empty>]
    update total = 0.0 to total + area(s) for s in stream(shapes)
    print.line("{total}")
7.14159