Last active
January 9, 2016 08:46
-
-
Save miklund/7d244612c466b09b22ed to your computer and use it in GitHub Desktop.
2011-07-25 Extending types in F#
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
# Title: | |
# Author: Mikael Lundin | |
# Link: http://blog.mikaellundin.name/2011/07/25/extending-types-in-fsharp.html |
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
type Hand (cards : Card list) = | |
member this.Cards = cards |
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
type Hand with | |
member x.IsRoyalStraightFlush = isRoyalStraightFlush x.Cards |
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
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 |
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
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