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 /∗Returns a list of type expressions from a type expression.∗/ /∗ Arguments: ======= te: the type expression Result: ======= TypeExpr_list: the corresponding list ∗/ typeExprToList : TypeExpr → TypeExpr ∗ typeExprToList(te) ≡ case te of TypeExprProduct(tep) → tep, → 〈te〉 end, /∗Returns the number of type expressions in a type expression.∗/ /∗ Arguments: ======= te: the type expression Results: ===== Int: the number of type expressions ∗/ getLengthTE : TypeExpr → Int getLengthTE(te) ≡ case te of TypeExprProduct(tep) → getLengthTEL(tep), BracketedTypeExpr(bte) → getLengthTE(bte), → 1 end, /∗Returns the number of type expressions in a type expression list.∗/ /∗ Arguments: ======= tel: the type expression list Results: ===== 222

C.1. FORMAL SPECIFICATION OF THE TRANSFORMER Int: the number of type expressions ∗/ getLengthTEL : TypeExpr ∗ → Int getLengthTEL(tel) ≡ if tel = 〈〉 then 0 else getLengthTE(hd tel) + getLengthTEL(tl tel) end, /∗Removes superfluous occurrences of UNIT from a type expression.∗/ /∗ Arguments: ======= te: the type expression Result: ======= TypeExpr: the resulting type expression ∗/ truncate : TypeExpr → TypeExpr truncate(tel) ≡ case tel of TypeLiteral(literal) → tel, TypeName(id) → tel, TypeExprProduct(telp) → if truncateTypeExprProduct(telp) = 〈〉 then TypeLiteral(UNIT) else if len truncateTypeExprProduct(telp) = 1 then hd truncateTypeExprProduct(telp) else TypeExprProduct( truncateTypeExprProduct(telp)) end end, TypeExprSet(tes) → tel, TypeExprList(te) → tel, TypeExprMap(tem) → tel, FunctionTypeExpr(te, fa, rd) → FunctionTypeExpr( truncate(te), fa, mk_ResultDesc( read_access_desc(rd), write_access_desc(rd), truncate(type_expr(rd)))), 223

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

Int: the number <strong>of</strong> type expressions<br />

∗/<br />

getLengthTEL : TypeExpr ∗ → Int<br />

getLengthTEL(tel) ≡<br />

if tel = 〈〉 then 0<br />

else getLengthTE(hd tel) + getLengthTEL(tl tel)<br />

end,<br />

/∗Removes superfluous occurrences <strong>of</strong> UNIT from<br />

a type expression.∗/<br />

/∗<br />

Arguments:<br />

=======<br />

te: the type expression<br />

Result:<br />

=======<br />

TypeExpr: the resulting type expression<br />

∗/<br />

truncate : TypeExpr → TypeExpr<br />

truncate(tel) ≡<br />

case tel <strong>of</strong><br />

TypeLiteral(literal) → tel,<br />

TypeName(id) → tel,<br />

TypeExprProduct(telp) →<br />

if truncateTypeExprProduct(telp) = 〈〉<br />

then TypeLiteral(UNIT)<br />

else<br />

if len truncateTypeExprProduct(telp) = 1<br />

then hd truncateTypeExprProduct(telp)<br />

else<br />

TypeExprProduct(<br />

truncateTypeExprProduct(telp))<br />

end<br />

end,<br />

TypeExprSet(tes) → tel,<br />

TypeExprList(te) → tel,<br />

TypeExprMap(tem) → tel,<br />

FunctionTypeExpr(te, fa, rd) →<br />

FunctionTypeExpr(<br />

truncate(te), fa,<br />

mk_ResultDesc(<br />

read_access_desc(rd),<br />

write_access_desc(rd),<br />

truncate(type_expr(rd)))),<br />

223

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

Saved successfully!

Ooh no, something went wrong!