Case Expressions

With case we can also pattern match on the value after some computations when there is no need to bind the intermediate result.

  1. plus :: (Integer, Integer) -> Integer
  2. plus (x, y) = x + y
  3. sumUpTo :: Integer -> (Integer, Integer) -> Boolean
  4. sumUpTo x p = case plus p of
  5. 10 -> true
  6. _ -> false
  7. > sumUpTo 1 (2,3)
  8. false
  9. > sumUpTo 1 (2,8)
  10. true