src/HOL/thy_data.ML
author wenzelm
Tue, 04 Nov 1997 16:49:35 +0100
changeset 4127 e0382d653d62
parent 4120 57c1e7d70960
child 4150 56025371fc02
permissions -rw-r--r--
tuned 'records' stuff;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4082
423d0d527cbc HOL theory data.
wenzelm
parents:
diff changeset
     1
(*  Title:      HOL/thy_data.ML
423d0d527cbc HOL theory data.
wenzelm
parents:
diff changeset
     2
    ID:         $Id$
423d0d527cbc HOL theory data.
wenzelm
parents:
diff changeset
     3
    Author:     Markus Wenzel, TU Muenchen
423d0d527cbc HOL theory data.
wenzelm
parents:
diff changeset
     4
4127
e0382d653d62 tuned 'records' stuff;
wenzelm
parents: 4120
diff changeset
     5
HOL theory data: simpset, claset, records, datatypes.
4082
423d0d527cbc HOL theory data.
wenzelm
parents:
diff changeset
     6
*)
423d0d527cbc HOL theory data.
wenzelm
parents:
diff changeset
     7
4127
e0382d653d62 tuned 'records' stuff;
wenzelm
parents: 4120
diff changeset
     8
(*for records*)
e0382d653d62 tuned 'records' stuff;
wenzelm
parents: 4120
diff changeset
     9
type record_info =
e0382d653d62 tuned 'records' stuff;
wenzelm
parents: 4120
diff changeset
    10
 {parent: string option,
e0382d653d62 tuned 'records' stuff;
wenzelm
parents: 4120
diff changeset
    11
  selectors: (string * ctyp) list};
e0382d653d62 tuned 'records' stuff;
wenzelm
parents: 4120
diff changeset
    12
e0382d653d62 tuned 'records' stuff;
wenzelm
parents: 4120
diff changeset
    13
(*for datatypes*)
4082
423d0d527cbc HOL theory data.
wenzelm
parents:
diff changeset
    14
type datatype_info =
423d0d527cbc HOL theory data.
wenzelm
parents:
diff changeset
    15
 {case_const: term,
423d0d527cbc HOL theory data.
wenzelm
parents:
diff changeset
    16
  case_rewrites: thm list,
423d0d527cbc HOL theory data.
wenzelm
parents:
diff changeset
    17
  constructors: term list,
423d0d527cbc HOL theory data.
wenzelm
parents:
diff changeset
    18
  induct_tac: string -> int -> tactic,
423d0d527cbc HOL theory data.
wenzelm
parents:
diff changeset
    19
  nchotomy: thm,
423d0d527cbc HOL theory data.
wenzelm
parents:
diff changeset
    20
  exhaustion: thm,
423d0d527cbc HOL theory data.
wenzelm
parents:
diff changeset
    21
  exhaust_tac: string -> int -> tactic,
423d0d527cbc HOL theory data.
wenzelm
parents:
diff changeset
    22
  case_cong: thm};
423d0d527cbc HOL theory data.
wenzelm
parents:
diff changeset
    23
4127
e0382d653d62 tuned 'records' stuff;
wenzelm
parents: 4120
diff changeset
    24
4082
423d0d527cbc HOL theory data.
wenzelm
parents:
diff changeset
    25
signature THY_DATA =
423d0d527cbc HOL theory data.
wenzelm
parents:
diff changeset
    26
sig
4127
e0382d653d62 tuned 'records' stuff;
wenzelm
parents: 4120
diff changeset
    27
  val get_records: theory -> record_info Symtab.table;
e0382d653d62 tuned 'records' stuff;
wenzelm
parents: 4120
diff changeset
    28
  val put_records: record_info Symtab.table -> theory -> theory;
4105
b84e8dacae08 datatypes;
wenzelm
parents: 4082
diff changeset
    29
  val get_datatypes_sg: Sign.sg -> datatype_info Symtab.table
b84e8dacae08 datatypes;
wenzelm
parents: 4082
diff changeset
    30
  val get_datatypes: theory -> datatype_info Symtab.table
b84e8dacae08 datatypes;
wenzelm
parents: 4082
diff changeset
    31
  val put_datatypes: datatype_info Symtab.table -> theory -> theory
4127
e0382d653d62 tuned 'records' stuff;
wenzelm
parents: 4120
diff changeset
    32
  val hol_data: (string * (object * (object -> object) *
e0382d653d62 tuned 'records' stuff;
wenzelm
parents: 4120
diff changeset
    33
    (object * object -> object) * (object -> unit))) list
4082
423d0d527cbc HOL theory data.
wenzelm
parents:
diff changeset
    34
end;
423d0d527cbc HOL theory data.
wenzelm
parents:
diff changeset
    35
423d0d527cbc HOL theory data.
wenzelm
parents:
diff changeset
    36
structure ThyData: THY_DATA =
423d0d527cbc HOL theory data.
wenzelm
parents:
diff changeset
    37
struct
423d0d527cbc HOL theory data.
wenzelm
parents:
diff changeset
    38
423d0d527cbc HOL theory data.
wenzelm
parents:
diff changeset
    39
4105
b84e8dacae08 datatypes;
wenzelm
parents: 4082
diff changeset
    40
(** datatypes **)
b84e8dacae08 datatypes;
wenzelm
parents: 4082
diff changeset
    41
b84e8dacae08 datatypes;
wenzelm
parents: 4082
diff changeset
    42
(* data kind 'datatypes' *)
4082
423d0d527cbc HOL theory data.
wenzelm
parents:
diff changeset
    43
423d0d527cbc HOL theory data.
wenzelm
parents:
diff changeset
    44
val datatypesK = "datatypes";
423d0d527cbc HOL theory data.
wenzelm
parents:
diff changeset
    45
exception DatatypeInfo of datatype_info Symtab.table;
423d0d527cbc HOL theory data.
wenzelm
parents:
diff changeset
    46
4105
b84e8dacae08 datatypes;
wenzelm
parents: 4082
diff changeset
    47
local
b84e8dacae08 datatypes;
wenzelm
parents: 4082
diff changeset
    48
  val empty = DatatypeInfo Symtab.null;
b84e8dacae08 datatypes;
wenzelm
parents: 4082
diff changeset
    49
b84e8dacae08 datatypes;
wenzelm
parents: 4082
diff changeset
    50
  fun prep_ext (x as DatatypeInfo _) = x;
b84e8dacae08 datatypes;
wenzelm
parents: 4082
diff changeset
    51
b84e8dacae08 datatypes;
wenzelm
parents: 4082
diff changeset
    52
  fun merge (DatatypeInfo tab1, DatatypeInfo tab2) =
b84e8dacae08 datatypes;
wenzelm
parents: 4082
diff changeset
    53
    DatatypeInfo (Symtab.merge (K true) (tab1, tab2));
b84e8dacae08 datatypes;
wenzelm
parents: 4082
diff changeset
    54
b84e8dacae08 datatypes;
wenzelm
parents: 4082
diff changeset
    55
  fun print (DatatypeInfo tab) =
b84e8dacae08 datatypes;
wenzelm
parents: 4082
diff changeset
    56
    Pretty.writeln (Pretty.strs ("datatypes:" :: map fst (Symtab.dest tab)));
b84e8dacae08 datatypes;
wenzelm
parents: 4082
diff changeset
    57
in
b84e8dacae08 datatypes;
wenzelm
parents: 4082
diff changeset
    58
  val datatypes_thy_data = (datatypesK, (empty, prep_ext, merge, print));
4127
e0382d653d62 tuned 'records' stuff;
wenzelm
parents: 4120
diff changeset
    59
end;
e0382d653d62 tuned 'records' stuff;
wenzelm
parents: 4120
diff changeset
    60
e0382d653d62 tuned 'records' stuff;
wenzelm
parents: 4120
diff changeset
    61
e0382d653d62 tuned 'records' stuff;
wenzelm
parents: 4120
diff changeset
    62
(* get and put datatypes *)
4120
57c1e7d70960 data kinds 'datatypes', data kinds 'records' added
narasche
parents: 4105
diff changeset
    63
4127
e0382d653d62 tuned 'records' stuff;
wenzelm
parents: 4120
diff changeset
    64
fun get_datatypes_sg sg =
e0382d653d62 tuned 'records' stuff;
wenzelm
parents: 4120
diff changeset
    65
  (case Sign.get_data sg datatypesK of
e0382d653d62 tuned 'records' stuff;
wenzelm
parents: 4120
diff changeset
    66
    DatatypeInfo tab => tab
e0382d653d62 tuned 'records' stuff;
wenzelm
parents: 4120
diff changeset
    67
  | _ => sys_error "get_datatypes_sg");
4120
57c1e7d70960 data kinds 'datatypes', data kinds 'records' added
narasche
parents: 4105
diff changeset
    68
4127
e0382d653d62 tuned 'records' stuff;
wenzelm
parents: 4120
diff changeset
    69
val get_datatypes = get_datatypes_sg o sign_of;
4120
57c1e7d70960 data kinds 'datatypes', data kinds 'records' added
narasche
parents: 4105
diff changeset
    70
4127
e0382d653d62 tuned 'records' stuff;
wenzelm
parents: 4120
diff changeset
    71
fun put_datatypes tab thy =
e0382d653d62 tuned 'records' stuff;
wenzelm
parents: 4120
diff changeset
    72
  Theory.put_data (datatypesK, DatatypeInfo tab) thy;
e0382d653d62 tuned 'records' stuff;
wenzelm
parents: 4120
diff changeset
    73
4082
423d0d527cbc HOL theory data.
wenzelm
parents:
diff changeset
    74
423d0d527cbc HOL theory data.
wenzelm
parents:
diff changeset
    75
4120
57c1e7d70960 data kinds 'datatypes', data kinds 'records' added
narasche
parents: 4105
diff changeset
    76
(** records **)
57c1e7d70960 data kinds 'datatypes', data kinds 'records' added
narasche
parents: 4105
diff changeset
    77
57c1e7d70960 data kinds 'datatypes', data kinds 'records' added
narasche
parents: 4105
diff changeset
    78
(* data kind 'records' *)
57c1e7d70960 data kinds 'datatypes', data kinds 'records' added
narasche
parents: 4105
diff changeset
    79
4127
e0382d653d62 tuned 'records' stuff;
wenzelm
parents: 4120
diff changeset
    80
val recordsK = "records";
e0382d653d62 tuned 'records' stuff;
wenzelm
parents: 4120
diff changeset
    81
exception Records of record_info Symtab.table;
e0382d653d62 tuned 'records' stuff;
wenzelm
parents: 4120
diff changeset
    82
e0382d653d62 tuned 'records' stuff;
wenzelm
parents: 4120
diff changeset
    83
4120
57c1e7d70960 data kinds 'datatypes', data kinds 'records' added
narasche
parents: 4105
diff changeset
    84
(* methods *)
57c1e7d70960 data kinds 'datatypes', data kinds 'records' added
narasche
parents: 4105
diff changeset
    85
57c1e7d70960 data kinds 'datatypes', data kinds 'records' added
narasche
parents: 4105
diff changeset
    86
local
57c1e7d70960 data kinds 'datatypes', data kinds 'records' added
narasche
parents: 4105
diff changeset
    87
  val empty = Records Symtab.null;
57c1e7d70960 data kinds 'datatypes', data kinds 'records' added
narasche
parents: 4105
diff changeset
    88
4127
e0382d653d62 tuned 'records' stuff;
wenzelm
parents: 4120
diff changeset
    89
  fun prep_ext (x as Records _) = x;
4120
57c1e7d70960 data kinds 'datatypes', data kinds 'records' added
narasche
parents: 4105
diff changeset
    90
4127
e0382d653d62 tuned 'records' stuff;
wenzelm
parents: 4120
diff changeset
    91
  fun merge (Records tab1, Records tab2) =
e0382d653d62 tuned 'records' stuff;
wenzelm
parents: 4120
diff changeset
    92
    Records (Symtab.merge (K true) (tab1, tab2));
4105
b84e8dacae08 datatypes;
wenzelm
parents: 4082
diff changeset
    93
4127
e0382d653d62 tuned 'records' stuff;
wenzelm
parents: 4120
diff changeset
    94
  fun print (Records tab) =
e0382d653d62 tuned 'records' stuff;
wenzelm
parents: 4120
diff changeset
    95
    let
e0382d653d62 tuned 'records' stuff;
wenzelm
parents: 4120
diff changeset
    96
      fun pretty_parent None = []
e0382d653d62 tuned 'records' stuff;
wenzelm
parents: 4120
diff changeset
    97
        | pretty_parent (Some name) = [Pretty.str (name ^ " +")];
e0382d653d62 tuned 'records' stuff;
wenzelm
parents: 4120
diff changeset
    98
e0382d653d62 tuned 'records' stuff;
wenzelm
parents: 4120
diff changeset
    99
      fun pretty_sel (c, T) = Pretty.block
e0382d653d62 tuned 'records' stuff;
wenzelm
parents: 4120
diff changeset
   100
        [Pretty.str (c ^ " :: "), Pretty.brk 1, Pretty.quote (Display.pretty_ctyp T)];
4105
b84e8dacae08 datatypes;
wenzelm
parents: 4082
diff changeset
   101
4127
e0382d653d62 tuned 'records' stuff;
wenzelm
parents: 4120
diff changeset
   102
      fun pretty_record (name, {parent, selectors}) =
e0382d653d62 tuned 'records' stuff;
wenzelm
parents: 4120
diff changeset
   103
        Pretty.big_list (name ^ " =") (pretty_parent parent @ map pretty_sel selectors);
e0382d653d62 tuned 'records' stuff;
wenzelm
parents: 4120
diff changeset
   104
    in
e0382d653d62 tuned 'records' stuff;
wenzelm
parents: 4120
diff changeset
   105
      seq (Pretty.writeln o pretty_record) (Symtab.dest tab)
e0382d653d62 tuned 'records' stuff;
wenzelm
parents: 4120
diff changeset
   106
    end;
e0382d653d62 tuned 'records' stuff;
wenzelm
parents: 4120
diff changeset
   107
in
e0382d653d62 tuned 'records' stuff;
wenzelm
parents: 4120
diff changeset
   108
  val record_thy_data = (recordsK, (empty, prep_ext, merge, print));
e0382d653d62 tuned 'records' stuff;
wenzelm
parents: 4120
diff changeset
   109
end;
e0382d653d62 tuned 'records' stuff;
wenzelm
parents: 4120
diff changeset
   110
4082
423d0d527cbc HOL theory data.
wenzelm
parents:
diff changeset
   111
4127
e0382d653d62 tuned 'records' stuff;
wenzelm
parents: 4120
diff changeset
   112
(* get and put records *)
4082
423d0d527cbc HOL theory data.
wenzelm
parents:
diff changeset
   113
4127
e0382d653d62 tuned 'records' stuff;
wenzelm
parents: 4120
diff changeset
   114
fun get_records thy =
e0382d653d62 tuned 'records' stuff;
wenzelm
parents: 4120
diff changeset
   115
  (case Theory.get_data thy recordsK of
e0382d653d62 tuned 'records' stuff;
wenzelm
parents: 4120
diff changeset
   116
    Records tab => tab
e0382d653d62 tuned 'records' stuff;
wenzelm
parents: 4120
diff changeset
   117
  | _ => sys_error "get_records");
e0382d653d62 tuned 'records' stuff;
wenzelm
parents: 4120
diff changeset
   118
e0382d653d62 tuned 'records' stuff;
wenzelm
parents: 4120
diff changeset
   119
fun put_records tab thy =
e0382d653d62 tuned 'records' stuff;
wenzelm
parents: 4120
diff changeset
   120
  Theory.put_data (recordsK, Records tab) thy;
e0382d653d62 tuned 'records' stuff;
wenzelm
parents: 4120
diff changeset
   121
4082
423d0d527cbc HOL theory data.
wenzelm
parents:
diff changeset
   122
423d0d527cbc HOL theory data.
wenzelm
parents:
diff changeset
   123
423d0d527cbc HOL theory data.
wenzelm
parents:
diff changeset
   124
(** hol_data **)
423d0d527cbc HOL theory data.
wenzelm
parents:
diff changeset
   125
423d0d527cbc HOL theory data.
wenzelm
parents:
diff changeset
   126
val hol_data =
4127
e0382d653d62 tuned 'records' stuff;
wenzelm
parents: 4120
diff changeset
   127
 [Simplifier.simpset_thy_data,          (*see Provers/simplifier.ML*)
e0382d653d62 tuned 'records' stuff;
wenzelm
parents: 4120
diff changeset
   128
  ClasetThyData.thy_data,               (*see Provers/classical.ML*)
e0382d653d62 tuned 'records' stuff;
wenzelm
parents: 4120
diff changeset
   129
  datatypes_thy_data,
e0382d653d62 tuned 'records' stuff;
wenzelm
parents: 4120
diff changeset
   130
  record_thy_data];
e0382d653d62 tuned 'records' stuff;
wenzelm
parents: 4120
diff changeset
   131
4082
423d0d527cbc HOL theory data.
wenzelm
parents:
diff changeset
   132
423d0d527cbc HOL theory data.
wenzelm
parents:
diff changeset
   133
end;