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 ======= vel: the original value expression list etl: the corresponding list of expected types Result: ======= Bool: the result ∗/ containsGen : ValueExpr ∗ × ExpType ∗ × TRANS × FUNC → Bool containsGen(vel, etl, trans, func) ≡ if vel = 〈〉 then false else if isGen(hd vel, hd etl, trans, func) ∧ ∼ returnsNonTOI(hd vel, hd etl, trans, func) then true else containsGen(tl vel, tl etl, trans, func) end end, /∗Checks if a value expression is a generator. ∗/ /∗ Arguments: ======= ve: the value expression et: the expected type of the value expression Result: ======= Bool: true if the value expression is a generator, false otherwise ∗/ isGen : ValueExpr × ExpType × TRANS × FUNC → Bool isGen(ve, et, trans, func) ≡ case ve of ApplicationExpr(vea, vel) → case vea of Make_ValueOrVariableName(vn) → write_list(func(id(vn))) = 〈〉, → false end, → case et of 238

C.1. FORMAL SPECIFICATION OF THE TRANSFORMER end, Known(te) → case te of TypeName(tn) → tn ∈ dom trans, TypeExprProduct(tel) → isGenProduct(ve, tel, trans, func), FunctionTypeExpr(arg, fa, res) → isGen( ve, Known(type_expr(res)), trans, func ), BracketedTypeExpr(bte) → isGen(ve, Known(bte), trans, func), → false end, Unknown → false end /∗Checks if a value expression is a generator. ∗/ /∗ Arguments: ======= ve: the value expression tel: the type of the value expression Result: ======= Bool: true if the value expression is a generator, false otherwise ∗/ isGenProduct : ValueExpr × TypeExpr ∗ × TRANS × FUNC → Bool isGenProduct(ve, tel, trans, func) ≡ if tel = 〈〉 then false else if isGen(ve, Known(hd tel), trans, func) then true else isGenProduct(ve, tl tel, trans, func) end end, /∗Checks if a value expression is a generator. ∗/ /∗ Arguments: ======= 239

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

end,<br />

Known(te) →<br />

case te <strong>of</strong><br />

TypeName(tn) → tn ∈ dom trans,<br />

TypeExprProduct(tel) →<br />

isGenProduct(ve, tel, trans, func),<br />

FunctionTypeExpr(arg, fa, res) →<br />

isGen(<br />

ve, Known(type_expr(res)), trans, func<br />

),<br />

BracketedTypeExpr(bte) →<br />

isGen(ve, Known(bte), trans, func),<br />

→ false<br />

end,<br />

Unknown → false<br />

end<br />

/∗Checks if a value expression is a generator.<br />

∗/<br />

/∗<br />

Arguments:<br />

=======<br />

ve: the value expression<br />

tel: the type <strong>of</strong> the value expression<br />

Result:<br />

=======<br />

Bool: true if the value expression is a generator,<br />

false otherwise<br />

∗/<br />

isGenProduct :<br />

ValueExpr × TypeExpr ∗ × TRANS × FUNC → Bool<br />

isGenProduct(ve, tel, trans, func) ≡<br />

if tel = 〈〉 then false<br />

else<br />

if isGen(ve, Known(hd tel), trans, func) then true<br />

else isGenProduct(ve, tl tel, trans, func)<br />

end<br />

end,<br />

/∗Checks if a value expression is a generator.<br />

∗/<br />

/∗<br />

Arguments:<br />

=======<br />

239

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

Saved successfully!

Ooh no, something went wrong!