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 (makeSequencingExpr( ApplicationExpr(ve, vel ′ ), type_expr(res), et, trans, func), types ′ ) else if containsGen( vel, typeExprToExpTypeList(arg), trans, func) ∧ ∼ onlyTOIArgument(vel, trans, types) then (makeSequencingExpr( TRFunctionAppl( ve, vel ′ , typeExprToExpTypeList(arg), func, trans, types), type_expr(res), et, trans, func), types ′ ) else (makeSequencingExpr( ApplicationExpr( ve, removeTOI( vel ′ , typeExprToExpTypeList(arg), trans)), type_expr(res), et, trans, func), types ′ ) end end end end else /∗List or map application.∗/ TRListMapAppl(ve, vel, et, func, trans, types) end, → TRListMapAppl(ve, vel, et, func, trans, types) end, /∗Transforms a function application.∗/ /∗ Arguments: ======= ve: the value expression 208

C.1. FORMAL SPECIFICATION OF THE TRANSFORMER vel: the arguments of the function application etl: the expected type of the arguments Result: ======= ValueExpr: the imperative version of the function expression ∗/ TRFunctionAppl : ValueExpr × ValueExpr ∗ × ExpType ∗ × FUNC × TRANS × TYPES → ValueExpr TRFunctionAppl(ve, vel, etl, func, trans, types) ≡ let (b, vl) = makeLetBinding(len vel, 0, 〈〉, 〈〉), vel ′ = makeValueExprList(vel, etl, vl, trans, func) in ApplicationExpr( ve, 〈LetExpr( 〈mk_LetDef( MakeBinding(makeBinding(b)), ProductExpr(vel))〉, ProductExpr(vel ′ ))〉) end, /∗Removes arguments of the type of interest.∗/ /∗ Arguments: ======= vel: the arguments of the function application etl: the expected type of the arguments Result: ======= ValueExpr_list: the resulting value expression list ∗/ removeTOI : ValueExpr ∗ × ExpType ∗ × TRANS → ValueExpr ∗ removeTOI(vel, etl, trans) ≡ if vel = 〈〉 then 〈〉 else case hd etl of 209

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

vel: the arguments <strong>of</strong> the function application<br />

etl: the expected type <strong>of</strong> the arguments<br />

Result:<br />

=======<br />

ValueExpr: the imperative version <strong>of</strong> the function<br />

expression<br />

∗/<br />

TRFunctionAppl :<br />

ValueExpr × ValueExpr ∗ × ExpType ∗ ×<br />

FUNC × TRANS × TYPES →<br />

ValueExpr<br />

TRFunctionAppl(ve, vel, etl, func, trans, types) ≡<br />

let<br />

(b, vl) = makeLetBinding(len vel, 0, 〈〉, 〈〉),<br />

vel ′ =<br />

makeValueExprList(vel, etl, vl, trans, func)<br />

in<br />

ApplicationExpr(<br />

ve,<br />

〈LetExpr(<br />

〈mk_LetDef(<br />

MakeBinding(makeBinding(b)),<br />

ProductExpr(vel))〉,<br />

ProductExpr(vel ′ ))〉)<br />

end,<br />

/∗Removes arguments <strong>of</strong> the type <strong>of</strong> interest.∗/<br />

/∗<br />

Arguments:<br />

=======<br />

vel: the arguments <strong>of</strong> the function application<br />

etl: the expected type <strong>of</strong> the arguments<br />

Result:<br />

=======<br />

ValueExpr_list: the resulting value expression<br />

list<br />

∗/<br />

removeTOI :<br />

ValueExpr ∗ × ExpType ∗ × TRANS →<br />

ValueExpr ∗<br />

removeTOI(vel, etl, trans) ≡<br />

if vel = 〈〉 then 〈〉<br />

else<br />

case hd etl <strong>of</strong><br />

209

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

Saved successfully!

Ooh no, something went wrong!