VDM-10 Language Manual
VDM-10 Language Manual
VDM-10 Language Manual
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
<strong>VDM</strong>-<strong>10</strong> <strong>Language</strong> <strong>Manual</strong><br />
Semantics: A pattern is always used in a context where it is matched to a value of a particular<br />
type. Matching consists of checking that the pattern can be matched to the value, and binding<br />
any pattern identifiers in the pattern to the corresponding values, i.e. making the identifiers<br />
denote those values throughout their scope. In some cases where a pattern can be used, a<br />
bind can be used as well (see next section). If a bind is used it simply means that additional<br />
information (a type or a set expression) is used to constrain the possible values which can<br />
match the given pattern.<br />
Matching is defined as follows<br />
1. A pattern identifier fits any type and can be matched to any value. If it is an identifier,<br />
that identifier is bound to the value; if it is the don’t-care symbol ‘-’, no binding occurs.<br />
2. A match value can only be matched against the value of itself; no binding occurs. If a<br />
match value is not a literal like e.g. 7 or it must be an expression enclosed in<br />
parentheses in order to discriminate it to a pattern identifier.<br />
3. A set enumeration pattern fits only set values. The patterns are matched to distinct<br />
elements of a set; all elements must be matched.<br />
4. A set union pattern fits only set values. The two patterns are matched to a partition of<br />
two subsets of a set. In the Toolbox the two subsets will always be chosen such that<br />
they are non-empty and disjoint.<br />
5. A sequence enumeration pattern fits only sequence values. Each pattern is matched<br />
against its corresponding element in the sequence value; the length of the sequence<br />
value and the number of patterns must be equal.<br />
6. A sequence concatenation pattern fits only sequence values. The two patterns are<br />
matched against two subsequences which together can be concatenated to form the<br />
original sequence value. In the Toolbox the two subsequences will always be chosen<br />
so that they are non-empty.<br />
7. A tuple pattern fits only tuples with the same number of elements. Each of the patterns<br />
are matched against the corresponding element in the tuple value.<br />
8. A record pattern fits only record values with the same tag. Each of the patterns are<br />
matched against the field of the record value. All the fields of the record must be<br />
matched.<br />
Examples: The simplest kind of pattern is the pattern identifier. An example of this is given in the<br />
following let expression:<br />
✞<br />
✡✝<br />
let top = GroupA(1)<br />
in top.sc<br />
Here the identifier top is bound to the head of the sequence GroupA and the identifier may<br />
then be used in the body of the let expression.<br />
74<br />
✆