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.

<strong>VDM</strong>-<strong>10</strong> <strong>Language</strong> <strong>Manual</strong><br />

Thus, a flat specification is made up of several definition blocks. However, only one state<br />

definition is allowed. The following is an example of a flat top-level specification:<br />

✞<br />

values<br />

st1 = mk_St([3,2,-9,11,5,3])<br />

state St of<br />

l:seq1 of nat<br />

end<br />

functions<br />

min_index : seq1 of nat -> nat<br />

min_index(l) ==<br />

if len l = 1<br />

then 1<br />

else let mi = min_index(tl l)<br />

in<br />

if l(mi+1) < hd l<br />

then mi+1<br />

else 1<br />

operations<br />

SelectionSort : nat ==> ()<br />

SelectionSort (i) ==<br />

if i < len l<br />

then (dcl temp: nat;<br />

dcl mi : nat := min_index(l(i,...,len l)) + i - 1;<br />

✡✝<br />

temp := l(mi);<br />

l(mi) := l(i);<br />

l(i) := temp;<br />

SelectionSort(i+1)<br />

)<br />

✆<br />

152

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

Saved successfully!

Ooh no, something went wrong!