Skip to content

Instantly share code, notes, and snippets.

@miklund
Last active January 9, 2016 08:46
Show Gist options
  • Save miklund/7d244612c466b09b22ed to your computer and use it in GitHub Desktop.
Save miklund/7d244612c466b09b22ed to your computer and use it in GitHub Desktop.
2011-07-25 Extending types in F#
# Title:
# Author: Mikael Lundin
# Link: http://blog.mikaellundin.name/2011/07/25/extending-types-in-fsharp.html
type Hand (cards : Card list) =
member this.Cards = cards
type Hand with
member x.IsRoyalStraightFlush = isRoyalStraightFlush x.Cards
let isRoyalStraightFlush (cards : Card list) =
match cards with
| Ace suit_1 :: King suit_2 :: Queen suit_3 :: Knave suit_4 :: ValueCard (suit_5, 10) :: []
when suit_1 = suit_2 && suit_2 = suit_3 && suit_3 = suit_4 && suit_4 = suit_5
-> true
| _ -> false
type Suit = | Spades | Hearts | Diamonds | Clubs
type Card =
| ValueCard of Suit * int
| Knave of Suit
| Queen of Suit
| King of Suit
| Ace of Suit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment