Hacker News new | ask | show | jobs
by tom_mellior 3292 days ago
Yes:

    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