Examples-0.1.0: Haskell code examples
Copyright© Frank Jung 2021-2023
LicenseGPL-3.0-only
Safe HaskellSafe-Inferred
LanguageHaskell2010

Cards

Description

From Tweag YouTube channel Introduction to Pattern Synonyms where Richard introduces GHC's feature of Pattern Synonyms, allowing programmers to abstract over a pattern.

Synopsis

Types

data Card Source #

Enumerated Cards including Honor cards.

Constructors

C2 
C3 
C4 
C5 
C6 
C7 
C8 
C9 
C10 
CHonor Honor 

Bundled Patterns

pattern CJack :: Card

Pattern synonyms can be "bundled" into exported Card type description.

pattern CQueen :: Card 
pattern CKing :: Card 
pattern CAce :: Card 

Instances

Instances details
Show Card Source #

Show instance for Card type. >>> show [CJack, CQueen, CKing, CAce, C7] "[J,Q,K,A,7]" >>> show [CHonor HJack, CHonor HQueen, CHonor HKing, CHonor HAce, C7] "[J,Q,K,A,7]" Here we want to keep show instance with Cards even though the 'Card type uses Honor cards.

Instance details

Defined in Cards

Methods

showsPrec :: Int -> Card -> ShowS #

show :: Card -> String #

showList :: [Card] -> ShowS #

Eq Card Source # 
Instance details

Defined in Cards

Methods

(==) :: Card -> Card -> Bool #

(/=) :: Card -> Card -> Bool #

Ord Card Source # 
Instance details

Defined in Cards

Methods

compare :: Card -> Card -> Ordering #

(<) :: Card -> Card -> Bool #

(<=) :: Card -> Card -> Bool #

(>) :: Card -> Card -> Bool #

(>=) :: Card -> Card -> Bool #

max :: Card -> Card -> Card #

min :: Card -> Card -> Card #

data Honor Source #

Honor cards.

Constructors

HJack 
HQueen 
HKing 
HAce 

Instances

Instances details
Eq Honor Source # 
Instance details

Defined in Cards

Methods

(==) :: Honor -> Honor -> Bool #

(/=) :: Honor -> Honor -> Bool #

Ord Honor Source # 
Instance details

Defined in Cards

Methods

compare :: Honor -> Honor -> Ordering #

(<) :: Honor -> Honor -> Bool #

(<=) :: Honor -> Honor -> Bool #

(>) :: Honor -> Honor -> Bool #

(>=) :: Honor -> Honor -> Bool #

max :: Honor -> Honor -> Honor #

min :: Honor -> Honor -> Honor #

Functions

checkEven :: Int -> Bool Source #

Check if a integer value is or odd.

>>> checkEven 42
True
>>> checkEven 11
False

numCardsToPlay :: Honor -> Natural Source #

Have provided all patterns (see COMPLETE above).