haskell-lectures/VL1/content/VL1_case_of.tex

10 lines
309 B
TeX

We can also pattern match on the result of a real expression, not just the input. For that, we write:
\begin{haskellcode}
f :: Int -> Bool
f x = case x - 2 of
2 -> True
5 -> True
y -> False
\end{haskellcode}
This allows more powerful pattern matching, especially when we define our own data structures.