I have a nested discriminatory union representing a deck of playing cards:
type Symbol =
| Seven
| Eight
| Nine
| Ten
| Jack
| Queen
| King
| Ace
type Card =
| Heart of Symbol
| Diamond of Symbol
| Spade of Symbol
| Club of Symbol
Now I want to write a function that returns the value of this card, which in my case does not depend on the card suit:
let GetValue (card : Card) =
match card with
| Heart(Seven) -> 0
| Diamond(Seven) -> 0
| Spade(Seven) -> 0
| Club(Seven) -> 0
...
It is obviously tiring to write. Is there a way to do something like this
let GetValue (card : Card) =
match card with
| _(Seven) | _(Eight) | _(Nine) -> 0
| _(Ten) -> 10
...
Many thanks.
dlkmp source
share