unison/unison-src/sheepshead.u

40 lines
828 B
Plaintext
Raw Normal View History

2019-06-19 17:51:11 +03:00
type Suit = Club | Spade | Heart | Diamond
2019-05-24 16:20:59 +03:00
type Card = Card Rank Suit
2019-06-19 17:51:11 +03:00
type Rank = A | K | Q | J | _10 | _9 | _8 | _7
2019-05-24 16:20:59 +03:00
type NonEmpty a = NonEmpty a [a]
2019-06-19 17:51:11 +03:00
use Rank A K Q J _10 _9 _8 _7
2019-05-24 16:20:59 +03:00
use Suit Club Spade Heart Diamond
use NonEmpty NonEmpty
2019-06-19 17:51:11 +03:00
use Optional Some None
2019-05-24 16:20:59 +03:00
namespace Suit where
2019-06-19 17:51:11 +03:00
all = [Club, Spade, Heart, Diamond]
2019-05-24 16:20:59 +03:00
namespace Rank where
2019-06-19 17:51:11 +03:00
all = [A, _10, K, Q, J, _9, _8, _7]
points = cases
2019-05-24 16:20:59 +03:00
A -> 11
2019-06-19 17:51:11 +03:00
_10 -> 10
2019-05-24 16:20:59 +03:00
K -> 4
Q -> 3
J -> 2
_ -> 0
toText = cases
2019-05-24 16:20:59 +03:00
A -> "A"
K -> "K"
Q -> "Q"
J -> "J"
2019-06-19 17:51:11 +03:00
_10 -> "10"
_9 -> "9"
_8 -> "8"
_7 -> "7"
2019-05-24 16:20:59 +03:00
namespace NonEmpty where
toList = cases
2019-05-24 16:20:59 +03:00
NonEmpty h t -> Sequence.cons h t
fromList : [a] -> Optional (NonEmpty a)
fromList l = match Sequence.at 0 l with
2019-06-19 17:51:11 +03:00
None -> None
Some a -> Some (NonEmpty a (Sequence.drop 1 l))