is_a recognizes sum-type variants; match is how you branch on them
Pitfall 8 of writing Soma, the programming language: a habit from another language, or a rule that surprises, with what the Soma compiler answers and the form to write.
let b = Box { w: 3 } // Box is a `variants` constructor of Shape
is_a(b, "Box") // true — the variant's name
is_a(b, "Shape") // true — its sum type's name
type_of(b) // "Variant" (a record literal is a "Map")
b.w // 3 — a struct variant's field reads with `.`// branch on the kind with an exhaustive match (a missing variant is a check error;
// a tuple variant's fields, `Pair(a, b)`, are only reachable this way)
on kind(s: Map) {
return match s {
Box { w } -> "Box of {w}"
Dot -> "Dot"
}
}(is_a / is_type also work on record literals: is_a(Game { x: 1 }, "Game") is true.)