> For the complete documentation index, see [llms.txt](https://haskell.hpmeducation.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://haskell.hpmeducation.com/defining-functions-working-with-functions/pattern-matching.md).

# Pattern Matching

**Pattern matching** is similar to conditional statements and allows us to choose different paths for our functions based on the patterns of their arguments. These **patterns can be direct values or more general patterns of arguments** that the function takes in. Much like in [guarded equations](/defining-functions-working-with-functions/conditionals/guarded-equations.md), the patterns are evaluated from top to bottom and the first one that matches the input arguments is selected for further evaluation. We can define our previous function `cardColour` using pattern matching with **direct values**:

```haskell
cardColour :: String -> String
cardColour "hearts" = "red"
cardColour "diamonds" = "red"
cardColour "spades" = "black"
cardColour "clubs" = "black"
cardColour _ = "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, we define multiple patterns for our function to account for different card suits and the wildcard character performs the same function as in the [`case`-`of`](/defining-functions-working-with-functions/conditionals/case-of-statements.md) example. Pattern matching gets more powerful when we use it with lists and tuples to build larger patterns.
