# Case-of Statements

There is another type of conditional statement in Haskell - `case`-`of`. It uses pattern matching to determine the expression to be evaluated. If you are familiar with switch statements from imperative programming, this is their equivalent in Haskell. The syntax is:

```haskell
case <EXPRESSION> of
  <PATTERN1> -> <EXPRESSION1>
  <PATTERN2> -> <EXPRESSION2>
  ...
  <PATTERNx> -> <EXPRESSIONx>
  _          -> <DEFAULT_EXPRESSION>
```

The `_` is a **wildcard character**. It is a useful tool for when we do not really care about what the value of the expression might be. In this case, whatever that value is – we know what we want to do if none of our previous patterns matches and assign it the default expression. For example, we could define a function that returns the colour of a playing card based on its suit:

```haskell
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."
```

That is, for the four valid suits we return their respective colours. Anything else is covered by the wildcard case and no matter what the value is, we always choose the same course of action.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://haskell.hpmeducation.com/defining-functions-working-with-functions/conditionals/case-of-statements.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
