Transformation of Applicative Specifications into Imperative ...

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

26.09.2013 Views

APPENDIX C. FORMAL SPECIFICATIONS OF TRANSFORMATIONS ie: the if expression et: the expected type of the if expression Results: ======= Bool: true if the if expression can be transformed, false otherwise ∗/ CheckIfExpr : IfExpr × ExpType × TYPINGS × FUNC × TRANS × ENV × TYPES → Bool × ENV × TYPES CheckIfExpr(ie, et, typings, func, trans, env, types) ≡ let (b1, env1, types1) = CheckValueExpr( condition(ie), Known(TypeLiteral(BOOL)), typings, func, trans, env, types), (b1 ′ , env1 ′ , types1 ′ ) = CheckValueExpr( if_case(ie), et, typings, func, trans, env1, types1), (b2, env2, types2) = CheckElsif( elsif_list(ie), et, typings, func, trans, env1, types1 ′ ), (b3, env3, types3) = CheckValueExpr( else_case(ie), et, typings, func, trans, env2, types2) in (b1 ∧ b1 ′ ∧ b2 ∧ b3, env3, types3) end, /∗Checks for transformability of an elsif list. ∗/ /∗ Arguments: ======= eil: the elsif list et: the expected type of the if expression Results: ======= Bool: true if the elsif list can be transformed, false otherwise 178

C.1. FORMAL SPECIFICATION OF THE TRANSFORMER ∗/ CheckElsif : Elsif ∗ × ExpType × TYPINGS × FUNC × TRANS × ENV × TYPES → Bool × ENV × TYPES CheckElsif(eil, et, typings, func, trans, env, types) ≡ if eil = 〈〉 then (true, env, types) else let (b1, env1, types1) = CheckValueExpr( condition(hd eil), Known(TypeLiteral(BOOL)), typings, func, trans, env, types), (b2, env2, types2) = CheckValueExpr( elsif_case(hd eil), et, typings, func, trans, env1, types1) in if (b1 ∧ b2) then CheckElsif( tl eil, et, typings, func, trans, env1, types2) else (false, env1, types2) end end end, /∗Checks for transformability of a case branch list. ∗/ /∗ Arguments: ======= cbl: the case branch list et: the expected type of the case expression Results: ======= Bool: true if the case branch list can be transformed, false otherwise ∗/ CheckCaseBranchList : CaseBranch ∗ × ExpType × TYPINGS × FUNC × 179

C.1. FORMAL SPECIFICATION OF THE TRANSFORMER<br />

∗/<br />

CheckElsif :<br />

Elsif ∗ × ExpType × TYPINGS × FUNC × TRANS ×<br />

ENV × TYPES →<br />

Bool × ENV × TYPES<br />

CheckElsif(eil, et, typings, func, trans, env, types) ≡<br />

if eil = 〈〉 then (true, env, types)<br />

else<br />

let<br />

(b1, env1, types1) =<br />

CheckValueExpr(<br />

condition(hd eil),<br />

Known(TypeLiteral(BOOL)), typings, func,<br />

trans, env, types),<br />

(b2, env2, types2) =<br />

CheckValueExpr(<br />

elsif_case(hd eil), et, typings, func,<br />

trans, env1, types1)<br />

in<br />

if (b1 ∧ b2)<br />

then<br />

CheckElsif(<br />

tl eil, et, typings, func, trans, env1,<br />

types2)<br />

else (false, env1, types2)<br />

end<br />

end<br />

end,<br />

/∗Checks for transformability <strong>of</strong> a case branch<br />

list.<br />

∗/<br />

/∗<br />

Arguments:<br />

=======<br />

cbl: the case branch list<br />

et: the expected type <strong>of</strong> the case expression<br />

Results:<br />

=======<br />

Bool: true if the case branch list can be transformed,<br />

false otherwise<br />

∗/<br />

CheckCaseBranchList :<br />

CaseBranch ∗ × ExpType × TYPINGS × FUNC ×<br />

179

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

Saved successfully!

Ooh no, something went wrong!