The feature of datatypes in ATS in largely taken from ML.
A datatype is like a tagged union type. For each datatype, there are some constructors associated with it, and these constructors are needed for constructing values of the datatype. As an example, the following syntax declares a datatype named intopt:
The code employed for illustration in this chapter plus some additional code for testing is available on-line.
Patterns in ATS can be defined inductively as follows:
Certain constant values such as integers, booleans, chars, floating point numbers, and strings are patterns.
The void-value () is a pattern.
The underscore symbol _ represents a special wildcard pattern.
Variables are patterns.
A tuple of patterns, either boxed or unboxed, is a pattern.
A record of patterns, either boxed or unboxed, is a pattern.
Given a constructor C, a pattern can be formed by applying C to a given list of patterns.
Given a variable x and a pattern pat, (x as pat) is a reference-pattern, where as is a keyword.
Some other forms of patterns will be introduced elsewhere.