  ## Pattern matching

When defining functions, you can define separate function bodies for different patterns. This leads to really neat code that's simple and readable.

```.css-e69dqy{position:relative;z-index:0;}.css-qq5p7o{padding:var(--chakra-space-5);border-radius:8px;margin-top:var(--chakra-space-8);margin-bottom:var(--chakra-space-8);background:#011627;-webkit-padding-start:0px;padding-inline-start:0px;-webkit-padding-end:0px;padding-inline-end:0px;overflow:hidden;}lucky :: (Integral a) => a -> String
lucky 7 = "LUCKY NUMBER SEVEN!"

Here is a more useful example with factorials:

```factorial :: (Integral a) => a -> a
factorial 0 = 1
factorial n = n * factorial (n - 1)```

Note: Pattern matching can also fail if the fallback case is not defined.

Pattern matching can also happen with list comprehensions:

```ghci> let xs = [(1,3), (4,3), (2,4), (5,3), (5,6), (3,1)]
ghci> [a+b | (a,b) <- xs]
[4,7,6,8,11,4]```

## Guards

```bmiTell :: (RealFloat a) => a -> String
bmiTell bmi
| bmi <= 18.5 = "You're underweight, you emo, you!"
| bmi <= 25.0 = "You're supposedly normal. Pffft, I bet you're ugly!"
| bmi <= 30.0 = "You're fat! Lose some weight, fatty!"
| otherwise   = "You're a whale, congratulations!"```

An example of a small `myCompare` function:

```myCompare :: (Ord a) => a -> a -> Ordering
a `myCompare` b
| a > b     = GT
| a == b    = EQ
| otherwise = LT
-- 3 `myCompare` 2 -> GT```

## Where bindings

```bmiTell :: (RealFloat a) => a -> a -> String
bmiTell weight height
| bmi <= 18.5 = "You're underweight, you emo, you!"
| bmi <= 25.0 = "You're supposedly normal. Pffft, I bet you're ugly!"
| bmi <= 30.0 = "You're fat! Lose some weight, fatty!"
| otherwise   = "You're a whale, congratulations!"
where bmi = weight / height ^ 2```