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 />
types<br />
digit = nat<br />
inv d == d < <strong>10</strong>;<br />
account:: holder : seq1 of char<br />
number : seq1 of digit<br />
branchcode : seq1 of digit<br />
balance: real<br />
epin: nat<br />
inv mk_account(holder, number, branchcode,-,-) ==<br />
len number = 8 and len branchcode = 6<br />
functions<br />
digval : digit -> nat<br />
digval(d) == d;<br />
deposit: account * real -> account<br />
deposit(acc,r) ==<br />
mu(acc,balance |-> acc.balance + r);<br />
withdrawal : account * real -> account<br />
withdrawal (acc,r) ==<br />
mu(acc,balance |-> acc.balance - r);<br />
isPin : account * nat -> bool<br />
isPin(acc,ep) ==<br />
ep = acc.epin;<br />
requestWithdrawal : account * nat -> bool<br />
requestWithdrawal (acc,amt) ==<br />
acc.balance > amt<br />
end BankAccount<br />
✡✝<br />
✆<br />
In this module we export two types and five functions. Note that since we have enumerated<br />
the entities we are exporting, but have not exported digit or account using the struct<br />
keyword, the internals of account values may not be accessed by other modules, neither<br />
may the invariant for digit. If such access is necessary, the types should be exported<br />
with the struct keyword, or all constructs in the module should be exported using the<br />
156