haskell-lectures/VL1/content/VL1_pattern_matching.tex
2015-04-21 14:07:42 +02:00

13 lines
562 B
TeX

In haskell we often use \textbf{pattern matching}. That means we define a function multiple times, but e.g. for different values of its input arguments. Let's see:
\pause
\begin{haskellcode}
isZero :: Int -> Bool
isZero 0 = True
isZero x = False
\end{haskellcode}
\vspace{\baselineskip}
So if we pass it 0, we get True. If we do not pass 0, we get False and the value we passed gets basically ignored.
\vspace{\baselineskip}
\\
\pause
What might happen if we remove the second or the third line? What is a \textbf{partial function} and a \textbf{total function}?