26.09.2013 Views

Transformation of Applicative Specifications into Imperative ...

Transformation of Applicative Specifications into Imperative ...

Transformation of Applicative Specifications into Imperative ...

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.

2.1. THE STACK EXAMPLE<br />

both sides without any type expressions Unit is inserted.<br />

Explicit value definitions <strong>of</strong> the Stack type is transformed <strong>into</strong> explicit<br />

function definitions, in which the stack variable is assigned the value expression<br />

<strong>of</strong> the explicit value definition.<br />

This leads to the concrete imperative specification given in Specification<br />

2.2.<br />

Specification 2.2 – Concrete imperative specification <strong>of</strong> a stack<br />

scheme I_STACK =<br />

class<br />

type<br />

Stack = Element ∗ ,<br />

Element<br />

end<br />

variable<br />

stack : Stack<br />

value<br />

empty : Unit → write stack Unit<br />

empty() ≡ stack := 〈〉,<br />

is_empty : Unit → read stack Bool<br />

is_empty() ≡ stack = 〈〉,<br />

push : Element → write stack Unit<br />

push(elem) ≡ stack := 〈elem〉 stack,<br />

pop : Unit ∼ → write stack Unit<br />

pop() ≡ stack := tl stack<br />

pre ∼ is_empty(),<br />

top : Unit ∼ → read stack Element<br />

top() ≡ hd stack<br />

pre ∼ is_empty()<br />

The following changes have been made:<br />

• The constant empty is transformed <strong>into</strong> an explicit function definition<br />

in which the stack variable is assigned the empty list.<br />

9

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

Saved successfully!

Ooh no, something went wrong!