25.07.2014 Views

VDM-10 Language Manual

VDM-10 Language Manual

VDM-10 Language Manual

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 3. Data Type Definitions<br />

• Built-in operators for values belonging to the type 4 .<br />

• Semantics of the built-in operators.<br />

• Examples illustrating how the built-in operators can be used.<br />

For each of the built-in operators the name, the symbol used and the type of the operator will<br />

be given together with a description of its semantics (except that the semantics of Equality and<br />

Inequality is not described, since it follows the usual semantics). In the semantics description<br />

identifiers refer to those used in the corresponding definition of operator type, e.g. m, m1, s, s1<br />

etc.<br />

3.2.1 Set Types<br />

A set is an unordered collection of values, all of the same type 5 , which is treated as a whole. All<br />

sets in <strong>VDM</strong> languages are finite, i.e. they contain only a finite number of elements. The elements<br />

of a set type can be arbitrarily complex, they could for example be sets themselves.<br />

In the following this convention will be used: A is an arbitrary type, S is a set type, s, s1, s2<br />

are set values, ss is a set of set values, e, e1, e2 and en are elements from the sets, bd1, bd2,<br />

. . . , bdm are bindings of identifiers to sets or types, and P is a logical predicate.<br />

Syntax:<br />

type = set type<br />

| . . . ;<br />

set type = ‘set of’, type ;<br />

Equation: S = set of A<br />

Constructors:<br />

Set enumeration: {e1, e2, ..., en} constructs a set of the enumerated elements.<br />

The empty set is denoted by {}.<br />

Set comprehension: {e | bd1, bd2, ..., bdm & P} constructs a set by evaluating<br />

the expression e on all the bindings for which the predicate P evaluates to true. A<br />

binding is either a set binding or a type binding 6 . A set bind bdn has the form pat1,<br />

..., patp in set s, where pati is a pattern (normally simply an identifier),<br />

and s is a set constructed by an expression. A type binding is similar, in the sense that<br />

in set is replaced by a colon and s is replaced with a type expression.<br />

4 These operators are used in either unary or binary expressions which are given with all the operators in section 6.3.<br />

5 Note however that it is always possible to find a common type for two values by the use of a union type (see section<br />

3.2.6.)<br />

6 Notice that type bindings cannot be executed by the interpreter because in general they are not executable (see section 8<br />

for further information about this).<br />

13

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!