5.7. Cons Pattern

The cons pattern matches the head and the tail of a nonempty list.

5.7.1. Syntax

[42]ConsPattern::= Pattern : Pattern  

5.7.2. Type

When a cons pattern Ph:Pt is matched against a list type List[T], pattern Ph is matched against type T, producing typing context Γh, and pattern Pt is matched against type List[T], producing typing context Γt. The typing context produced by the whole match is Γh ∪ Γt.

5.7.3. Examples

List Deconstruction
{- Publish the head and tail of a list as a tuple -}

val a = [1, 2, 3]
a >x:y> (x, y)

{-
OUTPUT:
(1, [2, 3])
-}

5.7.4. Related Links

Related Reference Topics

Related Tutorial Sections