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.
<strong>VDM</strong>-<strong>10</strong> <strong>Language</strong> <strong>Manual</strong><br />
be done with care in complex expressions. Note however that such operation calls are not<br />
allowed to throw exceptions.<br />
With such operation calls the order of evaluation can become important. Therefore the type<br />
checker will allow the user to enable or disable operation calls inside expressions.<br />
The tuple select expression is used to extract a particular component from a tuple. The<br />
meaning of the expression is if e evaluates to some tuple mk (v1,...,vN) and M is an<br />
integer in the range {1,...,N} then e.#M yields vM. If M lies outside {1,...,N} the<br />
expression is undefined.<br />
The function type instantiation is used for instantiating polymorphic functions with the<br />
proper types. It has the form:<br />
✞<br />
✡✝<br />
pf [ t1, ..., tn ]<br />
where pf is the name of a polymorphic function, and t1, ..., tn are types. The resulting<br />
function uses the types t1, ..., tn instead of the variable type names given in the<br />
function definition.<br />
Examples: Recall that GroupA is a sequence (page 54), GroupG is a map (page 55) and selection sort<br />
is a function (page 44):<br />
GroupA(1) ≡ mk Score(,2,0,1,6)<br />
GroupG() ≡ mk (2,1,0)<br />
GroupG().#2 ≡ 1<br />
selection sort([3,2,9,1,3]) ≡ [1,2,3,3,9]<br />
As an example of the use of polymorphic functions and function type instantiation, we use<br />
the example functions from section 5:<br />
✞<br />
≡<br />
let emptyInt = empty_bag[int]<br />
in<br />
plus_bag[int](-1, emptyInt())<br />
✆<br />
✡✝<br />
{ -1 |-> 1 }<br />
✆<br />
6.13 The New Expression (<strong>VDM</strong>++ and <strong>VDM</strong>-RT)<br />
Syntax: expression = . . .<br />
| new expression ;<br />
58