4.0  Patterns

Patterns are used to select case alternatives and are matched against values. For structured types, pattern matching is carried out from left to right, and components may also be nested patterns. A match is said either to succeed or fail as described below for the various pattern forms:

  1. Wildcard

    A match against the wildcard pattern always succeeds.

  2. Literal pattern

    The literal must be one of the following types:

    Int, Char, String

    The value is matched both by data type and equality.

  3. Variable pattern

    The value is bound to the name of the variable locally within the alternative.

  4. Nilary Data Constructor

    The value is matched both by data type and equivalence to the data constructor.

  5. Data Constructor with one or more components

    The value is first matched both by data type and equivalence to the data constructor. Secondly, each component of the data value is matched against the corresponding component pattern.


home

Last update: 11 October, 2005