by sevensevennine · 3y ago · 0 comments
Take a look at this example from the text, which contains an obvious domain modeling error while demonstrating cool things:
def suit := algebraicDataMatcher
| spade
| heart
| club
| diamond
def card := algebraicDataMatcher
| card suit (mod 13)
def poker cs :=
match cs as multiset card with
| [card $s $n, card #s #(n-1), card #s #(n-2), card #s #(n-3), card #s #(n-4)]
-> "Straight flush"
This matches a new kind of poker hand called the "wrap around straight flush," where a straight can wrap around Q, K, A, 2, 3. assertEqual "poker hand 1"
(poker [Card Spade 3, Card Spade 2, Card Spade 1, Card Spade 0, Card Spade 12])
"Straight flush"
TRUE
IOW, in their eagerness to demonstrate a really cool match on a mod 13 expression (something I haven't seen before), the author models the domain incorrectly.It's also somewhat confusing that the cards are modeled as n-1 - ace=0, 2=1, 3=2, etc, which is also confusing. I tried for about 10 minutes to fix it, but the only notation documentation I found is math that is way over my head.
No comments yet.