Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Syntax in Patterns

Pattern decomposition can also be used in the case, where and let.

mySum list =
  case list of
    [] -> 0
    x : xs -> x + mySum xs
divImod n m
  | n < m = (0, n)
  | otherwise = (q + 1, r)
  where
    (q, r) = divImod (n - m) m
firstAndsecond list =
  let first : second : rest = list
   in (first, second)