Created
October 8, 2013 19:01
-
-
Save misterspeedy/6889775 to your computer and use it in GitHub Desktop.
Type to represent a card
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// A playing card. | |
type Card = { Rank : Rank; Suit : Suit } | |
with | |
static member FromString (s : String) = | |
let rank, suit = | |
match s.Length with | |
| 2 -> s.Substring(0, 1), s.[1] | |
// The 10 case has three characters | |
| 3 -> s.Substring(0, 2), s.[2] | |
| _ -> raise (ArgumentException("Invalid card string: ", s)) | |
{ Rank = Rank.FromString rank; Suit = Suit.FromChar suit} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment