3 ms·
Haskell can, in fact, express the CardValue example using DataKinds. (I haven't written it out, though.)
by mrkgnao 9y ago
Haskell can, in fact, express the CardValue example using DataKinds. (I haven't written it out, though.)
- nv-vn 9y agoIf 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]