haskell-lectures/VL1/content/VL1_pattern_matching.tex

13 lines
1.2 KiB
TeX
Raw Normal View History

2015-04-23 20:40:13 +00:00
\ifger{In Haskell wird häufig das sogenannte}{In haskell we often use} \textbf{pattern matching}\ifger{ benutzt.}{.} \ifger{Das bedeutet, dass wir eine Funktion mehrmals definieren, aber z.b. für unterschiedliche Werte ihrer Eingabeargumente. Ungefähr so:}{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}
2015-05-01 14:41:24 +00:00
\ifger{D.h. wenn wir eine \hinline{0} übergeben, bekommen wir \hinline{True} zurück. Wenn wir keine \hinline{0} übergeben, dann bekommen wir \hinline{False} zurück, denn \hinline{x} in Zeile 3 ist ebenso pattern matching, allerdings matcht es jede Zahl.}{So if we pass it \hinline{0}, we get \hinline{True}. If we do not pass \hinline{0}, we get \hinline{False}, because \hinline{x} in line 3 is pattern matching as well, but matches every Int.}
\vspace{\baselineskip}
\\
2015-04-20 13:08:25 +00:00
\pause
2015-04-23 20:40:13 +00:00
\ifger{Was könnte passieren wenn wir die 2. oder 3. Zeile löschen? Was ist eine}{What might happen if we remove the second or the third line? What is a} \textbf{partial function} \ifger{und eine}{and a} \textbf{total function}?