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
669 B

  1. 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. These \verb#|# 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.