FCards - Defining Cards

04. A hand of cards

Lists, sets, sequences, and arrays

There are a bunch of different kinds of thing that can hold a collection of other things.

A list and array are pretty similar and is like a checklist of stuff, in that they are in order and we can add to the bottom or insert an item into the middle whenever we like.

A sequence is like some things coming off an assembly line. We don’t know how many they are (it could be infinite!!) and we take them as they come.

A set is more like a bag of things where no two things in the bag can have the same value.

We’ll generally use a List for our collections of things because it has some useful operators to join and split the list:

A hand of cards

A hand of cards is just a list of Card things

let hand = [Hearts Three; Diamonds Ten; Clubs King; Joker]

Code so far

type CardNumber =
  | Two 
  | Three
  | Four
  | Five
  | Six
  | Seven
  | Eight
  | Nine
  | Ten
  | Jack
  | Queen
  | King
  | Ace

type Card = 
  | Hearts of CardNumber
  | Diamonds of CardNumber
  | Clubs of CardNumber
  | Spades of CardNumber
  | Joker

let hand = [Hearts Three; Diamonds Ten; Clubs King; Joker]