Transformation of Applicative Specifications into Imperative ...
Transformation of Applicative Specifications into Imperative ... Transformation of Applicative Specifications into Imperative ...
CHAPTER 6. TRANSFORMATIONS A case expression is transformed by transforming the constituent value expressions and patterns. The patterns are transformed as follows: Value Literal Pattern A value literal pattern is transformed into itself. Name Pattern A name pattern is transformed into itself unless if it is of the type of interest. In that case the specification cannot be transformed as a pattern cannot consist of a variable. Wildcard Pattern A wildcard pattern is transformed into itself. Product Pattern A product pattern is of the form: (pattern1, pattern2, ..., patternn) A product pattern is transformed by transforming the constituent patterns. Record Pattern A record pattern is of the form: id(pattern1, pattern2, ..., patternn) A record pattern is transformed by transforming the constituent patterns. List Pattern A list pattern is of one of the forms: 〈pattern1, pattern2, ..., patternn〉 〈pattern1, pattern2, ..., patternn〉 patternn+1 A list pattern is transformed by transforming the constituent patterns. Introducing Assignment Expressions When transforming an applicative specification into the imperative counterpart it is necessary to establish assignment expressions when the value of the variable of the type of interest must be changed. This can happen in two situations. When dealing with a generator of the form: 50
6.4. TRANSFORMING EXPLICIT FUNCTION DEFINITIONS id : type_exprarg → type_exprres id(id1, ..., idn) ≡ value_expr the variable has to be assigned the proper value. There are two cases to consider. The type expression type_exprres of the result of the function is: 1. T. Transformation: The variable must be assigned the transformed value_expr, see function gen1 in Example 6.12. 2. a product in which T occurs. Transformation: The variable must be assigned the proper part of the product expression of value_expr, see function gen2 in Example 6.12. Example 6.12 – Assignment expressions in generators type T = Int value gen1 : Int → T gen1(i) ≡ i, ✄ gen2 : Int × Bool → T × Bool gen2(i, b) ≡ (i, b) type T = Int variable t : T value gen1 : Int → write t Unit gen1(i) ≡ t := i, gen2 : Int × Bool → write t Bool gen2(i, b) ≡ let (pa_0, pa_1) = (t := i, b) in (pa_1) end When dealing with implicit generators, that is when a value of the type of interest is expected, assignment expressions have to be established. This 51
- Page 16 and 17: LIST OF FIGURES xvi
- Page 18 and 19: CHAPTER 1. INTRODUCTION This stepwi
- Page 20 and 21: CHAPTER 1. INTRODUCTION 1. Formulat
- Page 22 and 23: CHAPTER 1. INTRODUCTION 1.7 Content
- Page 24 and 25: CHAPTER 2. GENERAL IDEA end value e
- Page 26 and 27: CHAPTER 2. GENERAL IDEA • In the
- Page 28 and 29: CHAPTER 2. GENERAL IDEA value incre
- Page 30 and 31: CHAPTER 3. TERMINOLOGY Expected Typ
- Page 32 and 33: CHAPTER 3. TERMINOLOGY Example 3.5
- Page 34 and 35: CHAPTER 3. TERMINOLOGY 18
- Page 36 and 37: CHAPTER 4. CONSTRAINTS further deve
- Page 38 and 39: CHAPTER 4. CONSTRAINTS of interest.
- Page 40 and 41: CHAPTER 4. CONSTRAINTS 24
- Page 42 and 43: CHAPTER 5. TRANSFORMABILITY scheme
- Page 44 and 45: CHAPTER 5. TRANSFORMABILITY 28
- Page 46 and 47: CHAPTER 6. TRANSFORMATIONS 6.2.1 Tr
- Page 48 and 49: CHAPTER 6. TRANSFORMATIONS Example
- Page 50 and 51: CHAPTER 6. TRANSFORMATIONS Applicat
- Page 52 and 53: CHAPTER 6. TRANSFORMATIONS object A
- Page 54 and 55: CHAPTER 6. TRANSFORMATIONS type T =
- Page 56 and 57: CHAPTER 6. TRANSFORMATIONS where ge
- Page 58 and 59: CHAPTER 6. TRANSFORMATIONS Ranged s
- Page 60 and 61: CHAPTER 6. TRANSFORMATIONS ✄ end
- Page 62 and 63: CHAPTER 6. TRANSFORMATIONS Value In
- Page 64 and 65: CHAPTER 6. TRANSFORMATIONS ✄ sche
- Page 68 and 69: CHAPTER 6. TRANSFORMATIONS is due t
- Page 70 and 71: CHAPTER 6. TRANSFORMATIONS 6.4.4 Tr
- Page 72 and 73: CHAPTER 6. TRANSFORMATIONS 56
- Page 74 and 75: CHAPTER 7. CORRECTNESS OF TRANSFORM
- Page 76 and 77: CHAPTER 7. CORRECTNESS OF TRANSFORM
- Page 78 and 79: CHAPTER 7. CORRECTNESS OF TRANSFORM
- Page 80 and 81: CHAPTER 7. CORRECTNESS OF TRANSFORM
- Page 82 and 83: CHAPTER 7. CORRECTNESS OF TRANSFORM
- Page 84 and 85: CHAPTER 7. CORRECTNESS OF TRANSFORM
- Page 86 and 87: CHAPTER 7. CORRECTNESS OF TRANSFORM
- Page 88 and 89: CHAPTER 8. SPECIFICATIONS The rewri
- Page 90 and 91: CHAPTER 8. SPECIFICATIONS RSL speci
- Page 92 and 93: CHAPTER 8. SPECIFICATIONS The FUNC
- Page 94 and 95: CHAPTER 8. SPECIFICATIONS out, that
- Page 96 and 97: CHAPTER 8. SPECIFICATIONS construct
- Page 98 and 99: CHAPTER 8. SPECIFICATIONS 8.4.1 Mor
- Page 100 and 101: CHAPTER 8. SPECIFICATIONS PRECOND_T
- Page 102 and 103: CHAPTER 8. SPECIFICATIONS if length
- Page 104 and 105: CHAPTER 8. SPECIFICATIONS subtypes.
- Page 106 and 107: CHAPTER 8. SPECIFICATIONS 8.5.2 Cha
- Page 108 and 109: CHAPTER 8. SPECIFICATIONS axiom [ m
- Page 110 and 111: CHAPTER 8. SPECIFICATIONS Specifica
- Page 112 and 113: CHAPTER 8. SPECIFICATIONS the lack
- Page 114 and 115: CHAPTER 9. IMPLEMENTATION OF THE TR
6.4. TRANSFORMING EXPLICIT FUNCTION DEFINITIONS<br />
id : type_exprarg → type_exprres<br />
id(id1, ..., idn) ≡ value_expr<br />
the variable has to be assigned the proper value. There are two cases to<br />
consider. The type expression type_exprres <strong>of</strong> the result <strong>of</strong> the function is:<br />
1. T.<br />
<strong>Transformation</strong>: The variable must be assigned the transformed<br />
value_expr, see function gen1 in Example 6.12.<br />
2. a product in which T occurs.<br />
<strong>Transformation</strong>: The variable must be assigned the proper part <strong>of</strong><br />
the product expression <strong>of</strong> value_expr, see function gen2 in Example<br />
6.12.<br />
Example 6.12 – Assignment expressions in generators<br />
type<br />
T = Int<br />
value<br />
gen1 : Int → T<br />
gen1(i) ≡ i,<br />
✄<br />
gen2 : Int × Bool → T × Bool<br />
gen2(i, b) ≡ (i, b)<br />
type<br />
T = Int<br />
variable<br />
t : T<br />
value<br />
gen1 : Int → write t Unit<br />
gen1(i) ≡ t := i,<br />
gen2 : Int × Bool → write t Bool<br />
gen2(i, b) ≡<br />
let (pa_0, pa_1) = (t := i, b) in (pa_1) end<br />
When dealing with implicit generators, that is when a value <strong>of</strong> the type<br />
<strong>of</strong> interest is expected, assignment expressions have to be established. This<br />
51