Polymorphism
Pyr uses enums with payloads and pattern matching for polymorphic dispatch. Define variants, match on them, and use UFCS for method-style calls.
enums model a closed set of types. each variant can carry its own data. |
|
a single function handles all variants via match. the compiler enforces exhaustiveness - add a variant and every match must handle it. |
|
$ pyr run polymorphism.pyr Rex says woof Rex Rex says woof Whiskers says meow Nemo blows 3 bubbles |