Skip to content

Pattern binding with = (total-only)

Kernel has only case, so even total bindings can lower via case. (A compiler may optimize to projections.)

SurfaceDesugaring
{ a: x } = e; bodycase ⟦e⟧ of | { a = x } -> ⟦body⟧
[h, ...t] = e; bodycase ⟦e⟧ of | (h :: t) -> ⟦body⟧
p = e; bodycase ⟦e⟧ of | ⟦p⟧ -> ⟦body⟧

Deep Path Destructuring

SurfaceDesugaring
{ a.b.c@{x} }⟦{ a: { b: { c: v#1@{x} } } }⟧

Pattern translation ⟦p⟧ uses the kernel pattern forms.

Whole-value binding @

SurfaceDesugaring
v@p (pattern)kernel pattern v @ ⟦p⟧
case e of | v@{ name: n } -> bcase ⟦e⟧ of | v @ { name = n } -> ⟦b⟧
binding: v@p = e; bodycase ⟦e⟧ of | v @ ⟦p⟧ -> ⟦body⟧

Pattern matching ?

Surface ? is syntactic sugar for case with ordered arms.

SurfaceDesugaring
e ? | p1 => b1 | p2 => b2case ⟦e⟧ of | ⟦p1⟧ -> ⟦b1⟧ | ⟦p2⟧ -> ⟦b2⟧
guard: | p when g => b| ⟦p⟧ -> case ⟦g⟧ of | True -> ⟦b⟧ | False -> nextArm (compiled as nested cases)

Multi-clause functions:

SurfaceDesugaring
f = | p1 => b1 | p2 => b2f = λx#1. case x#1 of | ⟦p1⟧ -> ⟦b1⟧ | ⟦p2⟧ -> ⟦b2⟧