VDM-10 Language Manual
VDM-10 Language Manual
VDM-10 Language Manual
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
Chapter 3. Data Type Definitions<br />
✡✝<br />
cons : Expr<br />
altn : Expr<br />
✆<br />
and let expr = mk Cond(mk Var("b",),mk Const(3),<br />
mk Var("v",nil)) then:<br />
is Cond(expr) ≡ true<br />
is Const(expr.cons) ≡ true<br />
is Var(expr.altn) ≡ true<br />
is Infix(expr.test) ≡ false<br />
Using union types we can extend the use of previously defined operators. For instance,<br />
interpreting = as a test over bool | nat we have<br />
1 = false ≡ false<br />
Similarly we can take use union types for taking unions of sets and concatenating sequences:<br />
{1,2} union {false,true} ≡ {1,2, false,true}<br />
[’a’,’b’]ˆ[,] ≡ [’a’,’b’, ,]<br />
In the set union, we take the union over sets of type nat | bool; for the sequence concatenation<br />
we are manipulating sequences of type char | | .<br />
3.2.7 The Object Reference Type (<strong>VDM</strong>++ and <strong>VDM</strong>-RT only)<br />
The object reference type has been added as part of the standard <strong>VDM</strong>-SL types. Therefore there<br />
is no direct way of restricting the use of object reference types (and thus of objects) in a way that<br />
conforms to pure object oriented principles; no additional structuring mechanisms than classes are<br />
foreseen. From these principles it follows that the use of an object reference type in combination<br />
with a type constructor (record, map, set, etc.) should be treated with caution.<br />
A value of the object reference type can be regarded as a reference to an object. If, for example,<br />
an instance variable (see section <strong>10</strong>) is defined to be of this type, this makes the class in which that<br />
instance variable is defined, a ‘client’ of the class in the object reference type; a clientship relation<br />
is established between the two classes.<br />
An object reference type is denoted by a class name. The class name in the object reference<br />
type must be the name of a class defined in the specification.<br />
The only operators defined for values of this type is the test for equality (‘=’) and inequality<br />
(‘’). Equality is based on references rather than values. That is, if o1 and o2 are two distinct<br />
objects which happen to have the same contents, o1 = o2 will yield false.<br />
Constructors Object references are constructed using the new expression (see section 6.13).<br />
Operators<br />
Operator Name Type<br />
t1 = t2 Equality A * A → bool<br />
t1 t2 Inequality A * A → bool<br />
27