I am trying to introduce standard playing cards in F #. My goal is to implement the Microsoft Solitaire clone (the one that comes with Windows), a game in which Costume, Face and Color are important. This exercise is mainly designed to learn some F #.
I reviewed the use of discriminated associations:
type Suit = | Diamonds | Hearts | Clubs | Spades type Color = | Red | Black type Face = Two | Three | Four | Five | Six | Seven | Eight | Nine | Ten | Jack | Queen | King | Ace
with record type for Card:
type Card = { suit: Suit; face: Face; color: Color; }
However, the color of the card can be inferred from his suit: all diamonds and hearts are red, and all clubs and spades are black. Costume cannot be determined only by color. Maybe something like this fits:
type Suit = | Diamonds of Color
But this does not seem right, as it allows for the wrong combinations, for example. Black hearts and red peaks.
My questions:
- What is the most idiomatic way to process a suit and color, given that color depends on the suit?
- Should the concept of color even be explicitly presented? Theoretically, one could simply replace all occurrences of color with matching patterns with diamonds or hearts (red) and clubs or spades (which are black).
source share