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.

8.3. SPECIFICATION OF THE TRANSFORMER<br />

The ENV map maps types <strong>of</strong> interest to the value names under which they<br />

are known at a certain point <strong>of</strong> execution. The ENV map is related to a<br />

function and not to the entire specification . The initial value <strong>of</strong> the ENV<br />

map is computed both in CheckValueDef and TRValueDef when dealing<br />

with explicit function definitions,<br />

The ENV map is used to check if the special scope rules defined in Chapter<br />

5 are fulfilled. Furthermore, it is used to decide which value names are<br />

<strong>of</strong> the type <strong>of</strong> interest and should be replaced with variables.<br />

When deciding if a value expression is transformable the following idea<br />

is pursued: A type identifier is mapped to a corresponding value name in<br />

ENV map, when the value name is in the scope. When the value name gets<br />

out <strong>of</strong> scope the entry is removed from the map. A value name can only be<br />

read from when it is in the scope, that is when it is in the range <strong>of</strong> the ENV<br />

map.<br />

When starting the check for transformability <strong>of</strong> the value expression <strong>of</strong> a<br />

function, the ENV map maps any type <strong>of</strong> interest occurring in the argument<br />

type <strong>of</strong> the function to the corresponding parameter name.<br />

During the check for transformability <strong>of</strong> let expressions the ENV map<br />

has to be updated according to the bindings in the let expressions to reflect<br />

the scopes <strong>of</strong> the value names. The content <strong>of</strong> the ENV map during a check<br />

for transformability is illustrated in Figure 8.1. By comparing this figure<br />

with Figure 5.1 on page 27 the connection between the scope rules and the<br />

ENV map should be obvious.<br />

type<br />

T<br />

value<br />

gen : ... → ... × T × ...<br />

f : T → ...<br />

f(t1) ≡ t1 + let t2 = t1 + gen(...) in t2 + gen(...) + ... end<br />

↑ ↑ ↑<br />

[ T ↦→ t1 ] [ T ↦→ t2 ] [ ]<br />

Figure 8.1: The ENV during transformability check<br />

The ENV map is a finite map, which means that it can hold at most one<br />

entry per type <strong>of</strong> interest. This conforms to the fact that there is only one<br />

placeholder for a variable, and that only one value name <strong>of</strong> a type <strong>of</strong> interest<br />

can be in scope at a certain point <strong>of</strong> execution.<br />

The most natural way to represent the ENV map is the reversed way,<br />

that is such that value names are mapped to type identifiers. But it turned<br />

77

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

Saved successfully!

Ooh no, something went wrong!