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 17. Top-level Specification (<strong>VDM</strong>-SL)<br />

Semantics: The exports section must be used to make constructs visible to other modules. Some<br />

or all of the defined constructs from a module can be exported. In the latter case, the keyword<br />

all is used. However, imported constructs are not exported from the module. If only part of<br />

the constructs are exported, the visible constructs with the appropriate signatures are stated.<br />

Normally, if a construct is visible to another module, that construct can be considered to be<br />

defined inside the module. However, with types and operations there are some exceptions:<br />

Types: If a type T is defined in module A and this type is also going to be used in module<br />

B, the type from module A has to be exported. This can be done in two ways:<br />

1. The name of the type is exported.<br />

2. The structure of the type is exported.<br />

If only the name of the type is exported, the other module cannot create values of type<br />

T. This means that the exporting module (A) must provide functions and/or operations<br />

to directly create and manipulate values of type T by means of the constructors related<br />

to the representation of T.<br />

If we export the structure of the type by using the keyword struct, the other module<br />

can create and manipulate values of type T (it can also use mk keyword and the is<br />

keyword for this type if it is a record type).<br />

If the type also defines an invariant, the invariant predicate function is only exported if<br />

the structure of the type is exported.<br />

Operations: In a module, a state that is global for the module can be defined. All operations<br />

within the module can manipulate that state. If operations are exported from a module,<br />

they manipulate the state in the exporting module, i.e. the state in the module where<br />

they are defined.<br />

If an exported function or an operation defines a pre- and/or post-condition, the corresponding<br />

predicate functions (see section 5) are also exported.<br />

Examples: Consider a model of a bank account. An account is characterised by the name of the<br />

holder, the account number, the bank branch at which the account is maintained, the balance,<br />

and an encrypted PIN code for the ATM card. We might model this as follows:<br />

✞<br />

module BankAccount<br />

exports types digit; account<br />

functions digval: digit -> nat;<br />

withdrawal: account * real -> account;<br />

isPin: account * nat -> bool;<br />

requestWithdrawal: account * nat -> bool<br />

definitions<br />

155

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

Saved successfully!

Ooh no, something went wrong!