Get updates via , Github, or RSS | About

Episode 8: Destructuring Jul 21, 2016

Destructuring is a way to bind variables using a syntax that is similar to type creation. It applies to lists, records, tuples and option types.

Examples

type MyType
  = AType Int


aFunction =
  let
    a = [1, 2, 3]
    _ =
      case a of
        [] -> 1
        h :: h' :: t -> 2
        h :: t -> 3

    b = { record = "r", number = 3, a = "" }
    { record, number } = b

    c = (1, "tuple")
    _ =
      case c of
        (x, "tuple") -> 1
        (_, "other") -> 2
        _ -> 3

    e = AType 3
    (AType x) = e
  in
   --…