|
|
|
|
|
by sgreben
4074 days ago
|
|
Sum types + exhaustiveness checking already do this, right? For this example: type animal = Cat | Dog
type action = Sound | Eat | Attack
let cat_sound () = printf "meow"
let cat_attack () = printf "scratch"
let dog_sound () = printf "woof"
let act animal action = match animal,action with
| Cat, Sound -> cat_sound ()
| Cat, Attack -> cat_attack ()
| Dog, Sound -> dog_sound ()
Compiling this yields: Warning 8: this pattern-matching is not exhaustive.
Here is an example of a value that is not matched:
(Dog, (Eat|Attack))
just as we'd like. |
|