equal
deleted
inserted
replaced
35 Record types are not primitive in Isabelle and have a delicate |
35 Record types are not primitive in Isabelle and have a delicate |
36 internal representation \cite{NaraschewskiW-TPHOLs98}, based on |
36 internal representation \cite{NaraschewskiW-TPHOLs98}, based on |
37 nested copies of the primitive product type. A \commdx{record} |
37 nested copies of the primitive product type. A \commdx{record} |
38 declaration introduces a new record type scheme by specifying its |
38 declaration introduces a new record type scheme by specifying its |
39 fields, which are packaged internally to hold up the perception of |
39 fields, which are packaged internally to hold up the perception of |
40 the record as a distinguished entity. Here is a very simply example: |
40 the record as a distinguished entity. Here is a simple example: |
41 *} |
41 *} |
42 |
42 |
43 record point = |
43 record point = |
44 Xcoord :: int |
44 Xcoord :: int |
45 Ycoord :: int |
45 Ycoord :: int |
56 |
56 |
57 text {* |
57 text {* |
58 We see above the ASCII notation for record brackets. You can also |
58 We see above the ASCII notation for record brackets. You can also |
59 use the symbolic brackets @{text \<lparr>} and @{text \<rparr>}. Record type |
59 use the symbolic brackets @{text \<lparr>} and @{text \<rparr>}. Record type |
60 expressions can be also written directly with individual fields. |
60 expressions can be also written directly with individual fields. |
61 The type name above is merely an abbreviations. |
61 The type name above is merely an abbreviation. |
62 *} |
62 *} |
63 |
63 |
64 constdefs |
64 constdefs |
65 pt2 :: "\<lparr>Xcoord :: int, Ycoord :: int\<rparr>" |
65 pt2 :: "\<lparr>Xcoord :: int, Ycoord :: int\<rparr>" |
66 "pt2 \<equiv> \<lparr>Xcoord = -45, Ycoord = 97\<rparr>" |
66 "pt2 \<equiv> \<lparr>Xcoord = -45, Ycoord = 97\<rparr>" |
150 lemma "point.more cpt1 = \<lparr>col = Green\<rparr>" |
150 lemma "point.more cpt1 = \<lparr>col = Green\<rparr>" |
151 by (simp add: cpt1_def) |
151 by (simp add: cpt1_def) |
152 |
152 |
153 text {* |
153 text {* |
154 We see that the colour part attached to this @{typ point} is a |
154 We see that the colour part attached to this @{typ point} is a |
155 (rudimentary) record in its own right, namely @{text "\<lparr>col = |
155 rudimentary record in its own right, namely @{text "\<lparr>col = |
156 Green\<rparr>"}. In order to select or update @{text col}, this fragment |
156 Green\<rparr>"}. In order to select or update @{text col}, this fragment |
157 needs to be put back into the context of the parent type scheme, say |
157 needs to be put back into the context of the parent type scheme, say |
158 as @{text more} part of another @{typ point}. |
158 as @{text more} part of another @{typ point}. |
159 |
159 |
160 To define generic operations, we need to know a bit more about |
160 To define generic operations, we need to know a bit more about |
343 of the original record type) and returns a fixed record, removing |
343 of the original record type) and returns a fixed record, removing |
344 any additional fields. |
344 any additional fields. |
345 |
345 |
346 \end{itemize} |
346 \end{itemize} |
347 |
347 |
348 These functions merely provide handsome abbreviations for standard |
348 These functions provide useful abbreviations for standard |
349 record expressions involving constructors and selectors. The |
349 record expressions involving constructors and selectors. The |
350 definitions, which are \emph{not} unfolded by default, are made |
350 definitions, which are \emph{not} unfolded by default, are made |
351 available by the collective name of @{text defs} (@{text |
351 available by the collective name of @{text defs} (@{text |
352 point.defs}, @{text cpoint.defs}, etc.). |
352 point.defs}, @{text cpoint.defs}, etc.). |
353 |
353 |