Tuples & unit

Implemented

(a, b), (), tuple types and patterns, and let (a, b) = e.

A tuple is written (a, b), its type (int, string), and the empty tuple () has type unit. Underneath it is Unison’s own nested Tuple ending in unit, so it hashes exactly as Unison’s tuple does (checked against UCM). (x) is plain grouping: there are no one-element tuples.

let pair = (): (int, string) => (1, "one")

let swap = (p: (int, string)): (string, int) => {
let (n, s) = p;
(s, n)
}

let first = (p: (int, string)): int => switch p {
| (n, _) => n
}

let nothing = (): unit => ()
Verified through UCM. Note the semicolon after a destructuring let.

A destructuring let (a, b) = e is a one-arm switch over the rest of the block, and let () = e matches unit. Tuple patterns work in switch too; the unit pattern () is a real constructor pattern and hashes differently from _.

Open and narrow: a function type cannot be a tuple element in a type, and no one-tuples.