src/HOL/ex/Records.thy
author wenzelm
Thu, 21 Sep 2000 15:58:13 +0200
changeset 10052 5fa8d8d5c852
child 10357 0d0cac129618
permissions -rw-r--r--
renamed HOL/ex/Points to HOL/ex/Records;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10052
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
     1
(*  Title:      HOL/ex/Records.thy
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
     2
    ID:         $Id$
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
     3
    Author:     Wolfgang Naraschewski and Markus Wenzel, TU Muenchen
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
     4
    License:    GPL (GNU GENERAL PUBLIC LICENSE)
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
     5
*)
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
     6
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
     7
header {* Using extensible records in HOL -- points and coloured points *}
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
     8
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
     9
theory Records = Main:
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
    10
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
    11
subsection {* Points *}
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
    12
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
    13
record point =
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
    14
  x :: nat
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
    15
  y :: nat
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
    16
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
    17
text {*
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
    18
 Apart many other things, above record declaration produces the
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
    19
 following theorems:
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
    20
*}
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
    21
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
    22
thm "point.simps"
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
    23
thm "point.iffs"
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
    24
thm "point.update_defs"
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
    25
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
    26
text {*
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
    27
 The set of theorems "point.simps" is added automatically to the
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
    28
 standard simpset, "point.iffs" is added to the claset and simpset.
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
    29
*}
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
    30
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
    31
text {*
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
    32
  Record declarations define new type abbreviations:
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
    33
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
    34
    point = "(| x :: nat, y :: nat |)"
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
    35
    'a point_scheme = "(| x :: nat, y :: nat, ... :: 'a |)"
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
    36
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
    37
  Extensions `...' must be in type class `more'!
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
    38
*}
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
    39
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
    40
consts foo1 :: point
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
    41
consts foo2 :: "(| x :: nat, y :: nat |)"
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
    42
consts foo3 :: "'a => ('a::more) point_scheme"
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
    43
consts foo4 :: "'a => (| x :: nat, y :: nat, ... :: 'a |)"
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
    44
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
    45
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
    46
subsubsection {* Introducing concrete records and record schemes *}
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
    47
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
    48
defs
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
    49
  foo1_def: "foo1 == (| x = 1, y = 0 |)"
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
    50
  foo3_def: "foo3 ext == (| x = 1, y = 0, ... = ext |)"
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
    51
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
    52
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
    53
subsubsection {* Record selection and record update *}
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
    54
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
    55
constdefs
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
    56
  getX :: "('a::more) point_scheme => nat"
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
    57
  "getX r == x r"
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
    58
  setX :: "('a::more) point_scheme => nat => 'a point_scheme"
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
    59
  "setX r n == r (| x := n |)"
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
    60
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
    61
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
    62
subsubsection {* Some lemmas about records *}
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
    63
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
    64
text {* Basic simplifications *}
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
    65
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
    66
lemma "point.make n p = (| x = n, y = p |)"
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
    67
  by simp
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
    68
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
    69
lemma "x (| x = m, y = n, ... = p |) = m"
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
    70
  by simp
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
    71
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
    72
lemma "(| x = m, y = n, ... = p |) (| x:= 0 |) = (| x = 0, y = n, ... = p |)"
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
    73
  by simp
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
    74
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
    75
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
    76
text {* Equality of records *}
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
    77
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
    78
lemma "n = n' ==> p = p' ==> (| x = n, y = p |) = (| x = n', y = p' |)"
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
    79
  -- "introduction of concrete record equality"
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
    80
  by simp
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
    81
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
    82
lemma "(| x = n, y = p |) = (| x = n', y = p' |) ==> n = n'"
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
    83
  -- "elimination of concrete record equality"
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
    84
  by simp
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
    85
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
    86
lemma "r (| x := n |) (| y := m |) = r (| y := m |) (| x := n |)"
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
    87
  -- "introduction of abstract record equality"
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
    88
  by simp
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
    89
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
    90
lemma "r (| x := n |) = r (| x := n' |) ==> n = n'"
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
    91
  -- "elimination of abstract record equality (manual proof)"
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
    92
proof -
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
    93
  assume "r (| x := n |) = r (| x := n' |)" (is "?lhs = ?rhs")
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
    94
  hence "x ?lhs = x ?rhs" by simp
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
    95
  thus ?thesis by simp
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
    96
qed
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
    97
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
    98
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
    99
text {* Surjective pairing *}
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
   100
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
   101
lemma "r = (| x = x r, y = y r |)"
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
   102
  by simp
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
   103
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
   104
lemma "r = (| x = x r, y = y r, ... = more r |)"
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
   105
  by simp
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
   106
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
   107
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
   108
text {* Splitting quantifiers: the !!r is NECESSARY here *}
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
   109
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
   110
lemma "!!r. r (| x := n |) (| y := m |) = r (| y := m |) (| x := n |)"
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
   111
proof record_split
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
   112
  fix x y more
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
   113
  show "(| x = x, y = y, ... = more |)(| x := n, y := m |) =
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
   114
        (| x = x, y = y, ... = more |)(| y := m, x := n |)"
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
   115
    by simp
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
   116
qed
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
   117
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
   118
lemma "!!r. r (| x := n |) (| x := m |) = r (| x := m |)"
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
   119
proof record_split
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
   120
  fix x y more
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
   121
  show "(| x = x, y = y, ... = more |)(| x := n, x := m |) =
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
   122
        (| x = x, y = y, ... = more |)(| x := m |)"
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
   123
    by simp
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
   124
qed
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
   125
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
   126
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
   127
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
   128
text {* Concrete records are type instances of record schemes *}
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
   129
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
   130
constdefs
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
   131
  foo5 :: nat
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
   132
  "foo5 == getX (| x = 1, y = 0 |)"
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
   133
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
   134
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
   135
text {* Manipulating the `...' (more) part *}
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
   136
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
   137
constdefs
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
   138
  incX :: "('a::more) point_scheme => 'a point_scheme"
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
   139
  "incX r == (| x = Suc (x r), y = y r, ... = point.more r |)"
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
   140
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
   141
lemma "!!r n. incX r = setX r (Suc (getX r))"
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
   142
proof (unfold getX_def setX_def incX_def)
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
   143
  show "!!r n. (| x = Suc (x r), y = y r, ... = more r |) = r(| x := Suc (x r) |)"
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
   144
    by record_split simp
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
   145
qed
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
   146
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
   147
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
   148
text {* alternative definition *}
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
   149
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
   150
constdefs
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
   151
  incX' :: "('a::more) point_scheme => 'a point_scheme"
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
   152
  "incX' r == r (| x := Suc (x r) |)"
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
   153
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
   154
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
   155
subsection {* Coloured points: record extension *}
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
   156
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
   157
datatype colour = Red | Green | Blue
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
   158
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
   159
record cpoint = point +
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
   160
  colour :: colour
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
   161
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
   162
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
   163
text {*
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
   164
  The record declaration defines new type constructors:
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
   165
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
   166
    cpoint = (| x :: nat, y :: nat, colour :: colour |)
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
   167
    'a cpoint_scheme = (| x :: nat, y :: nat, colour :: colour, ... :: 'a |)
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
   168
*}
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
   169
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
   170
consts foo6 :: cpoint
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
   171
consts foo7 :: "(| x :: nat, y :: nat, colour :: colour |)"
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
   172
consts foo8 :: "('a::more) cpoint_scheme"
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
   173
consts foo9 :: "(| x :: nat, y :: nat, colour :: colour, ... :: 'a |)"
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
   174
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
   175
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
   176
text {* Functions on point schemes work for cpoints as well *}
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
   177
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
   178
constdefs
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
   179
  foo10 :: nat
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
   180
  "foo10 == getX (| x = 2, y = 0, colour = Blue |)"
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
   181
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
   182
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
   183
subsubsection {* Non-coercive structural subtyping *}
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
   184
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
   185
text {* foo11 has type cpoint, not type point --- Great! *}
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
   186
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
   187
constdefs
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
   188
  foo11 :: cpoint
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
   189
  "foo11 == setX (| x = 2, y = 0, colour = Blue |) 0"
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
   190
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
   191
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
   192
subsection {* Other features *}
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
   193
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
   194
text {* field names contribute to record identity *}
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
   195
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
   196
record point' =
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
   197
  x' :: nat
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
   198
  y' :: nat
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
   199
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
   200
text {* May not apply @{term getX} to @{term "(| x' = 2, y' = 0 |)"} *}
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
   201
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
   202
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
   203
text {* Polymorphic records *}
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
   204
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
   205
record 'a point'' = point +
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
   206
  content :: 'a
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
   207
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
   208
types cpoint'' = "colour point''"
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
   209
5fa8d8d5c852 renamed HOL/ex/Points to HOL/ex/Records;
wenzelm
parents:
diff changeset
   210
end