26.09.2013 Views

Transformation of Applicative Specifications into Imperative ...

Transformation of Applicative Specifications into Imperative ...

Transformation of Applicative Specifications into Imperative ...

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

D.2. FORMAL SPECIFICATION OF THE TRANSFORMER IN RSL1<br />

/∗**** TypeExpr ****∗/<br />

typeExprToList : TypeExpr → TypeExpr ∗<br />

typeExprToList(te) ≡<br />

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

TypeExprProduct(tep) → tep,<br />

→ 〈te〉<br />

end,<br />

getLengthTE : TypeExpr → Int<br />

getLengthTE(te) ≡<br />

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

TypeExprProduct(tep) → getLengthTEL(tep),<br />

BracketedTypeExpr(bte) → getLengthTE(bte),<br />

→ 1<br />

end,<br />

getLengthTEL : TypeExpr ∗ → Int<br />

getLengthTEL(tel) ≡<br />

if tel = 〈〉 then 0<br />

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

end,<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 lengthTE(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 />

407

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

Saved successfully!

Ooh no, something went wrong!