Transformation of Applicative Specifications into Imperative ...

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

26.09.2013 Views

CHAPTER 8. SPECIFICATIONS PRECOND_TYPES :: preCond : OptionalPreCondition typesMap : TYPES value TROptPreCondition : OptionalPreCondition × ExpType × FUNC × TRANS × TYPES → PRECOND_TYPES TROptPreCondition(precond, et, func, trans, types) ≡ case precond of PreCondition(ve) → mk_PRECOND_TYPES( PreCondition( valueExpr( TRValueExpr(ve, et, func, trans, types)) ), typesMap( TRValueExpr(ve, et, func, trans, types))), NoPreCondition → mk_PRECOND_TYPES(NoPreCondition, types) end 8.4.3 Lack of Operators Only a small subset of operators are included in the RSL1 subset. The lack of these operators makes it necessary to implement their functionality using functions. Some of the operators are straight forward to implement, whereas some limit the functionality of the transformer. An example of the first kind is the inequality operator = and the negation operator ∼. A solution to the lack of the these operators can be seen in Example 8.4. Example 8.4 – Lack of operators – inequality and negation RSL specification: . if tel = 〈〉 then (false, mk_FormalFunctionParameter(〈〉), env, 84

. 8.4. SPECIFICATION OF THE TRANSFORMER IN RSL1 types, prlet) else (true, mk_FormalFunctionParameter(〈〉), env, types, prlet) end RSL1 specification: . . if not(tel = 〈〉) then mk_BOOL_FFP_ENV_TYPES_LDL( false, mk_FormalFunctionParameter(〈〉), env, types, prlet) else mk_BOOL_FFP_ENV_TYPES_LDL( true, mk_FormalFunctionParameter(〈〉), env, types, prlet) end not : Bool → Bool not(b) ≡ if b then false else true end An example of the second kind is the lack of the minus operator. As the minus operator cannot be implemented directly using the limited range of operators in RSL1, it is necessary to implement this in a way that limits the functionality of transformer. This can be seen in Example 8.5. The limitation is that the minusOne function can only handle numbers from 1 through 10 and that it only is capable of subtracting by one. Example 8.5 – Lack of operators – minus RSL specification: toExpTypeList : ExpType × Nat → ExpType ∗ toExpTypeList(et, length) ≡ 85

CHAPTER 8. SPECIFICATIONS<br />

PRECOND_TYPES ::<br />

preCond : OptionalPreCondition typesMap : TYPES<br />

value<br />

TROptPreCondition :<br />

OptionalPreCondition × ExpType × FUNC × TRANS ×<br />

TYPES →<br />

PRECOND_TYPES<br />

TROptPreCondition(precond, et, func, trans, types) ≡<br />

case precond <strong>of</strong><br />

PreCondition(ve) →<br />

mk_PRECOND_TYPES(<br />

PreCondition(<br />

valueExpr(<br />

TRValueExpr(ve, et, func, trans, types))<br />

),<br />

typesMap(<br />

TRValueExpr(ve, et, func, trans, types))),<br />

NoPreCondition →<br />

mk_PRECOND_TYPES(NoPreCondition, types)<br />

end<br />

8.4.3 Lack <strong>of</strong> Operators<br />

Only a small subset <strong>of</strong> operators are included in the RSL1 subset. The lack<br />

<strong>of</strong> these operators makes it necessary to implement their functionality using<br />

functions. Some <strong>of</strong> the operators are straight forward to implement, whereas<br />

some limit the functionality <strong>of</strong> the transformer.<br />

An example <strong>of</strong> the first kind is the inequality operator = and the negation<br />

operator ∼. A solution to the lack <strong>of</strong> the these operators can be seen in<br />

Example 8.4.<br />

Example 8.4 – Lack <strong>of</strong> operators – inequality and negation<br />

RSL specification:<br />

.<br />

if tel = 〈〉<br />

then<br />

(false, mk_FormalFunctionParameter(〈〉), env,<br />

84

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

Saved successfully!

Ooh no, something went wrong!