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.
 
 
 

15 lines
452 B

  1. Again, we can do pattern matching on lists.
  2. \begin{haskellcode}
  3. listLen :: [Integer] -> Integer
  4. listLen [] = 0
  5. listLen (x:xs) = 1 + listLen xs
  6. \end{haskellcode}
  7. \pause
  8. We can also nest pattern matching:
  9. \begin{haskellcode}
  10. sumEveryTwo :: [Integer] -> [Integer]
  11. sumEveryTwo [] = 0
  12. sumEveryTwo (x:[]) = [x]
  13. sumEveryTwo (x:(y:zs)) = (x + y) : sumEveryTwo zs
  14. \end{haskellcode}
  15. Note that \code{(x:(y:zs))} may also be written as \code{(x:y:zs)}.