Case-of Statements
case <EXPRESSION> of
<PATTERN1> -> <EXPRESSION1>
<PATTERN2> -> <EXPRESSION2>
...
<PATTERNx> -> <EXPRESSIONx>
_ -> <DEFAULT_EXPRESSION>cardColour :: String -> String
cardColour suit =
case suit of
"hearts" -> "red"
"diamonds" -> "red"
"spades" -> "black"
"clubs" -> "black"
_ -> "I am not familiar with this card suit."
ghci> cardColour "diamonds"
"red"
ghci> cardColour "ace"
"I am not familiar with this card suit."Last updated