119 getX :: "('a::more) point_scheme \<Rightarrow> int" |
119 getX :: "('a::more) point_scheme \<Rightarrow> int" |
120 "getX r == Xcoord r" |
120 "getX r == Xcoord r" |
121 setX :: "[('a::more) point_scheme, int] \<Rightarrow> 'a point_scheme" |
121 setX :: "[('a::more) point_scheme, int] \<Rightarrow> 'a point_scheme" |
122 "setX r a == r (| Xcoord := a |)" |
122 "setX r a == r (| Xcoord := a |)" |
123 extendpt :: "'a \<Rightarrow> ('a::more) point_scheme" |
123 extendpt :: "'a \<Rightarrow> ('a::more) point_scheme" |
124 "extendpt ext == (| Xcoord = #15, Ycoord = 0, ... = ext |)" |
124 "extendpt ext == (| Xcoord = 15, Ycoord = 0, ... = ext |)" |
125 text{*not sure what this is for!*} |
125 text{*not sure what this is for!*} |
126 |
126 |
127 |
127 |
128 text {* |
128 text {* |
129 \medskip Concrete records are type instances of record schemes. |
129 \medskip Concrete records are type instances of record schemes. |
130 *} |
130 *} |
131 |
131 |
132 lemma "getX (| Xcoord = #64, Ycoord = #36 |) = #64" |
132 lemma "getX (| Xcoord = 64, Ycoord = 36 |) = 64" |
133 by (simp add: getX_def) |
133 by (simp add: getX_def) |
134 |
134 |
135 |
135 |
136 text {* \medskip Manipulating the `...' (more) part. beware: EACH record |
136 text {* \medskip Manipulating the `...' (more) part. beware: EACH record |
137 has its OWN more field, so a compound name is required! *} |
137 has its OWN more field, so a compound name is required! *} |
138 |
138 |
139 constdefs |
139 constdefs |
140 incX :: "('a::more) point_scheme \<Rightarrow> 'a point_scheme" |
140 incX :: "('a::more) point_scheme \<Rightarrow> 'a point_scheme" |
141 "incX r == \<lparr>Xcoord = (Xcoord r) + #1, Ycoord = Ycoord r, \<dots> = point.more r\<rparr>" |
141 "incX r == \<lparr>Xcoord = (Xcoord r) + 1, Ycoord = Ycoord r, \<dots> = point.more r\<rparr>" |
142 |
142 |
143 constdefs |
143 constdefs |
144 setGreen :: "[colour, ('a::more) point_scheme] \<Rightarrow> cpoint" |
144 setGreen :: "[colour, ('a::more) point_scheme] \<Rightarrow> cpoint" |
145 "setGreen cl r == (| Xcoord = Xcoord r, Ycoord = Ycoord r, col = cl |)" |
145 "setGreen cl r == (| Xcoord = Xcoord r, Ycoord = Ycoord r, col = cl |)" |
146 |
146 |
147 |
147 |
148 text {* works (I think) for ALL extensions of type point? *} |
148 text {* works (I think) for ALL extensions of type point? *} |
149 |
149 |
150 lemma "incX r = setX r ((getX r) + #1)" |
150 lemma "incX r = setX r ((getX r) + 1)" |
151 by (simp add: getX_def setX_def incX_def) |
151 by (simp add: getX_def setX_def incX_def) |
152 |
152 |
153 text {* An equivalent definition. *} |
153 text {* An equivalent definition. *} |
154 lemma "incX r = r \<lparr>Xcoord := (Xcoord r) + #1\<rparr>" |
154 lemma "incX r = r \<lparr>Xcoord := (Xcoord r) + 1\<rparr>" |
155 by (simp add: incX_def) |
155 by (simp add: incX_def) |
156 |
156 |
157 |
157 |
158 |
158 |
159 text {* |
159 text {* |
160 Functions on @{text point} schemes work for type @{text cpoint} as |
160 Functions on @{text point} schemes work for type @{text cpoint} as |
161 well. *} |
161 well. *} |
162 |
162 |
163 lemma "getX \<lparr>Xcoord = #23, Ycoord = #10, col = Blue\<rparr> = #23" |
163 lemma "getX \<lparr>Xcoord = 23, Ycoord = 10, col = Blue\<rparr> = 23" |
164 by (simp add: getX_def) |
164 by (simp add: getX_def) |
165 |
165 |
166 |
166 |
167 subsubsection {* Non-coercive structural subtyping *} |
167 subsubsection {* Non-coercive structural subtyping *} |
168 |
168 |
169 text {* |
169 text {* |
170 Function @{term setX} can be applied to type @{typ cpoint}, not just type |
170 Function @{term setX} can be applied to type @{typ cpoint}, not just type |
171 @{typ point}, and returns a result of the same type! *} |
171 @{typ point}, and returns a result of the same type! *} |
172 |
172 |
173 lemma "setX \<lparr>Xcoord = #12, Ycoord = 0, col = Blue\<rparr> #23 = |
173 lemma "setX \<lparr>Xcoord = 12, Ycoord = 0, col = Blue\<rparr> 23 = |
174 \<lparr>Xcoord = #23, Ycoord = 0, col = Blue\<rparr>" |
174 \<lparr>Xcoord = 23, Ycoord = 0, col = Blue\<rparr>" |
175 by (simp add: setX_def) |
175 by (simp add: setX_def) |
176 |
176 |
177 |
177 |
178 subsection {* Other features *} |
178 subsection {* Other features *} |
179 |
179 |