Transformation of Applicative Specifications into Imperative ...

Transformation of Applicative Specifications into Imperative ... Transformation of Applicative Specifications into Imperative ...

26.09.2013 Views

CHAPTER 6. TRANSFORMATIONS Applicative single typing ✄ Imperative single typing U → V ✄ U → V T → V ✄ Unit → read t V U → T ✄ U → write t Unit T → T ✄ Unit → read t write t Unit T × U → V ✄ U → read t V U → T × V ✄ U → write t V T × U → T × V ✄ U → read t write t V Table 6.1: Transformation of single typings. T is a type of interest with associated variable t, U and V are not of the type of interest. superfluous read access descriptor is included in order to ease the verification of the transformation rules, see Chapter 7. The reason for these transformations is that instead of referring to the type of interest using parameters, you refer to the corresponding variable of the type of interest, and instead of returning a type of interest, you assign the results to the variable of the type of interest. 6.4.2 Transforming Formal Function Applications When transforming formal function applications all occurrences of parameters of the type of interest are removed as in the following example where t is a parameter of the type of interest: f(u, t, v) ≡ ... ✄ f(u, v) ≡ ... If the type of interest is an abbreviation type and this is exploited in the formal function application, all parameters forming the type of interest are removed as in the following example where (u, v) is of the type of interest: f(p, (u, v), q) ≡ ... ✄ f(p, q) ≡ ... When this is done it is necessary to establish a let expression in the transformation of the value expression at the right hand side of the equivalence operator ≡: f(p, q) ≡ let (u, v) = t in ... end This is done in order to be able to refer to the parameters removed as these are not variables that can be referred to as t can. 34

6.4. TRANSFORMING EXPLICIT FUNCTION DEFINITIONS 6.4.3 Transforming Value Expressions in Function Definitions This section concerns the transformation of value expressions in function definitions. First a general introduction to the transformations is given and then the different kinds of value expressions are discussed one by one. Introduction to Transforming Value Expressions A function can always be transformed by making the value expression a function application of the corresponding applicative function in which all parameters of the types of interest are replaced by the corresponding variables, see Example 6.3. However, since the goal of the transformation is to remove all occurrences of objects of the applicative specification this is not satisfactory and can be improved in most cases by exploiting the following idea: Example 6.3 – General transformation scheme A_SPEC = class type T = ..., U = ..., V = ... value obs1 : T → U obs1(t) ≡ ..., obs2 : T × U → V obs2(t, u) ≡ ..., gen1 : T → T gen1(t) ≡ ..., gen2 : T × U → T gen2(t, u) ≡ ..., gen3 : T → T × U gen3(t) ≡ ... gen4 : T × U → T × V gen4(t, u) ≡ ... end ✄ scheme I_SPEC = class 35

CHAPTER 6. TRANSFORMATIONS<br />

<strong>Applicative</strong> single typing ✄ <strong>Imperative</strong> single typing<br />

U → V ✄ U → V<br />

T → V ✄ Unit → read t V<br />

U → T ✄ U → write t Unit<br />

T → T ✄ Unit → read t write t Unit<br />

T × U → V ✄ U → read t V<br />

U → T × V ✄ U → write t V<br />

T × U → T × V ✄ U → read t write t V<br />

Table 6.1: <strong>Transformation</strong> <strong>of</strong> single typings. T is a type <strong>of</strong> interest with<br />

associated variable t, U and V are not <strong>of</strong> the type <strong>of</strong> interest.<br />

superfluous read access descriptor is included in order to ease the verification<br />

<strong>of</strong> the transformation rules, see Chapter 7.<br />

The reason for these transformations is that instead <strong>of</strong> referring to the<br />

type <strong>of</strong> interest using parameters, you refer to the corresponding variable <strong>of</strong><br />

the type <strong>of</strong> interest, and instead <strong>of</strong> returning a type <strong>of</strong> interest, you assign<br />

the results to the variable <strong>of</strong> the type <strong>of</strong> interest.<br />

6.4.2 Transforming Formal Function Applications<br />

When transforming formal function applications all occurrences <strong>of</strong> parameters<br />

<strong>of</strong> the type <strong>of</strong> interest are removed as in the following example where t<br />

is a parameter <strong>of</strong> the type <strong>of</strong> interest:<br />

f(u, t, v) ≡ ...<br />

✄<br />

f(u, v) ≡ ...<br />

If the type <strong>of</strong> interest is an abbreviation type and this is exploited in the<br />

formal function application, all parameters forming the type <strong>of</strong> interest are<br />

removed as in the following example where (u, v) is <strong>of</strong> the type <strong>of</strong> interest:<br />

f(p, (u, v), q) ≡ ...<br />

✄<br />

f(p, q) ≡ ...<br />

When this is done it is necessary to establish a let expression in the transformation<br />

<strong>of</strong> the value expression at the right hand side <strong>of</strong> the equivalence<br />

operator ≡:<br />

f(p, q) ≡ let (u, v) = t in ... end<br />

This is done in order to be able to refer to the parameters removed as<br />

these are not variables that can be referred to as t can.<br />

34

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

Saved successfully!

Ooh no, something went wrong!