You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

10 lines
1.3 KiB

  1. \ifger{Wie sieht es mit \emph{Rekursion} aus? Wir wollen den Modulo von einem beliebigen \emph{Int} zu \emph{2} definieren.}{How about \emph{recursion}? Let's define the modulo of any \emph{Int} to \emph{2}.}
  2. \pause
  3. \begin{haskellcode}
  4. mod2 :: Int -> Int
  5. mod2 x
  6. | x - 2 == 0 = 0
  7. | x - 2 < 0 = x
  8. | otherwise = mod2 (x - 2)
  9. \end{haskellcode}
  10. \ifger{Diese}{These} \hinline{|} \ifger{Zeichen nennt man \textbf{guards} und sie sind dem \emph{pattern matching} sehr ähnlich. Sie werden von oben nach unten abgearbeitet. Wenn die Bedingung auf der linken Seite der Gleichung wahr ist, dann gibt die gesamte Funktion das heraus, was auf der rechten Seite der Gleichung steht. Ansonsten wird die nächste Zeile ausprobiert. \hinline{otherwise} in der letzten Zeile ist lediglich \hinline{True}, um dieses Konstrukt lesbarer zu machen und fungiert quasi als allgemeines \emph{else}.}{things above are called \textbf{guards} and are similar to \emph{pattern matching}. They are processed in order. If the condition on the left side of the equation is true, then it returns what stands on the right side of the equation. If it's false, then it processes the next line.\\ \hinline{otherwise} on the last line is just defined as \hinline{True}, to make these constructs easier to read and catch all other cases of input.}