4 ms·
If I understand it correctly, it should work in OCaml too with polymorphic variants.
by nv-vn 9y ago
If I understand it correctly, it should work in OCaml too with polymorphic variants.
- tom_mellior 9y agoYes: type card_value = [`Jack | `Queen | `King | `Ace | `Num of int] (* not really necessary, but nice to have *) type royal_card = [`Jack | `Queen | `King] let royal_value (card: royal_card): int = match card with `Jack | `Queen | `King -> 1 When trying to abuse this, you get a static type error at compile time: royal_value `Ace;; Error: This expression has type [> `Ace ] but an expression was expected of type royal_card The second variant type does not allow tag(s) `Ace
- deleted 9y ago[deleted]