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 Value Infix Expressions A value infix expression has the following form: value_expr1 infix_op value_expr2 A value infix expression is transformed by transforming the constituent value expressions. The infix operator stays the same. Value Prefix Expressions A value prefix expression has the following form: prefix_op value_expr A value prefix expression is transformed by transforming the constituent value expression. The prefix operator stays the same. Let Expressions A let expression takes the following form: let letbinding1 = value_expr1, . letbindingn = value_exprn in value_exprn+1 end A let expression is transformed by transforming the constituent value expressions. Furthermore, the let bindings have to be transformed in order to comply with the return values of the corresponding value expressions. The reason for this is that in the imperative specification generators do not return values of the type of interest. There are three cases to consider when dealing with a let expression of the form: let letbinding = value_expr in ... end 46

6.4. TRANSFORMING EXPLICIT FUNCTION DEFINITIONS The type of value_expr: 1. does not contain T. Transformation: The letbinding is transformed into itself, see function f1 in Example 6.11. 2. is T. Transformation: A so called "dummy" binding is inserted in order to keep the let expression and the order of the let definitions, see function f2 in Example 6.11. 3. is a product in which T occurs. Transformation: The bindings corresponding to the values of the type of interest are removed from the letbinding, see function f3 in Example 6.11 Example 6.11 – Transformation of let expressions scheme A_SPEC = class type T = Int end value f1 : T → Int f1(x) ≡ let z = obs(x) in z end, f2 : Int → Int f2(x) ≡ let x1 = gen1(x) in x1 + 1 end, f3 : Int → Int f3(x) ≡ let (x1, z) = gen2(x) in z end, obs : T → Int obs(x) ≡ x, gen1 : Int → T gen1(x) ≡ x + 1, gen2 : Int → T × Int gen2(x) ≡ (x + 1, x − 1) 47

6.4. TRANSFORMING EXPLICIT FUNCTION DEFINITIONS<br />

The type <strong>of</strong> value_expr:<br />

1. does not contain T.<br />

<strong>Transformation</strong>: The letbinding is transformed <strong>into</strong> itself, see function<br />

f1 in Example 6.11.<br />

2. is T.<br />

<strong>Transformation</strong>: A so called "dummy" binding is inserted in order to<br />

keep the let expression and the order <strong>of</strong> the let definitions, see function<br />

f2 in Example 6.11.<br />

3. is a product in which T occurs.<br />

<strong>Transformation</strong>: The bindings corresponding to the values <strong>of</strong> the<br />

type <strong>of</strong> interest are removed from the letbinding, see function f3 in<br />

Example 6.11<br />

Example 6.11 – <strong>Transformation</strong> <strong>of</strong> let expressions<br />

scheme A_SPEC =<br />

class<br />

type<br />

T = Int<br />

end<br />

value<br />

f1 : T → Int<br />

f1(x) ≡ let z = obs(x) in z end,<br />

f2 : Int → Int<br />

f2(x) ≡ let x1 = gen1(x) in x1 + 1 end,<br />

f3 : Int → Int<br />

f3(x) ≡ let (x1, z) = gen2(x) in z end,<br />

obs : T → Int<br />

obs(x) ≡ x,<br />

gen1 : Int → T<br />

gen1(x) ≡ x + 1,<br />

gen2 : Int → T × Int<br />

gen2(x) ≡ (x + 1, x − 1)<br />

47

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

Saved successfully!

Ooh no, something went wrong!