25.07.2014 Views

VDM-10 Language Manual

VDM-10 Language Manual

VDM-10 Language Manual

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 5<br />

Function Definitions<br />

In the <strong>VDM</strong> languages we can define first order and higher order functions. A higher order function<br />

is either a Curried function (a function that returns a function as result), or a function that takes<br />

functions as arguments. Furthermore, both first order and higher order functions can be polymorphic.<br />

In <strong>VDM</strong>++ and <strong>VDM</strong>-RT functions are automatically available in a static form (i.e. without<br />

having an instance of the defining class). Thus there is no need to use the static keyword that<br />

can be used for operations in <strong>VDM</strong>++ and <strong>VDM</strong>-RT. . In general, the syntax for the definition of<br />

a function is:<br />

function definitions = ‘functions’, [ access function definition ],<br />

{ ‘;’ }, access function definition function definition, [ ‘;’ ] ;<br />

access function definition = [ access ], function definition ;<br />

access = ‘public’<br />

| ‘private’<br />

| ‘protected’ ;<br />

function definition = explicit function definition<br />

| implicit function definition<br />

| extended explicit function definition ;<br />

explicit function definition = identifier,<br />

[ type variable list ], ‘:’, function type,<br />

identifier, parameters list, ‘==’,<br />

function body,<br />

[ ‘pre’, expression ],<br />

[ ‘post’, expression ],<br />

[ ‘measure’, name ] ;<br />

implicit function definition = identifier, [ type variable list ],<br />

parameter types, identifier type pair list,<br />

[ ‘pre’, expression ],<br />

‘post’, expression ;<br />

35

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

Saved successfully!

Ooh no, something went wrong!