src/HOL/record.ML
author nipkow
Mon, 09 Feb 1998 14:40:59 +0100
changeset 4612 26764de50c74
parent 4574 b922012cc142
permissions -rw-r--r--
Used THEN_ALL_NEW.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4454
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
     1
(*  Title:      HOL/record.ML
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
     2
    ID:         $Id$
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
     3
    Author:     Wolfgang Naraschewski and Markus Wenzel, TU Muenchen
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
     4
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
     5
Internal interface for records.
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
     6
*)
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
     7
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
     8
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
     9
signature RECORD =
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
    10
sig
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
    11
  val add_record: 
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
    12
    (string list * bstring) -> string option -> 
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
    13
      (bstring * string) list -> theory -> theory
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
    14
  val add_record_i: 
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
    15
    (string list * bstring) -> (typ list * string) option -> 
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
    16
      (bstring * typ) list -> theory -> theory
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
    17
end;
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
    18
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
    19
structure Record: RECORD =
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
    20
struct
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
    21
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
    22
val base = Sign.base_name; 
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
    23
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
    24
(* FIXME move to Pure/library.ML *)
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
    25
fun set_minus xs [] = xs
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
    26
  | set_minus xs (y::ys) = set_minus (xs \ y) ys;
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
    27
(* FIXME *)
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
    28
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
    29
(* FIXME move to Pure/sign.ML *)
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
    30
fun of_sort sg = 
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
    31
  Sorts.of_sort 
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
    32
    (#classrel (Type.rep_tsig (#tsig (Sign.rep_sg sg))))
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
    33
    (#arities (Type.rep_tsig (#tsig (Sign.rep_sg sg))));
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
    34
(* FIXME *)
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
    35
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
    36
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
    37
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
    38
(** record info **)
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
    39
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
    40
fun get_record thy name = 
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
    41
  let val table = ThyData.get_records thy
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
    42
  in
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
    43
    Symtab.lookup (table, name)
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
    44
  end;
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
    45
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
    46
fun put_record thy name info = 
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
    47
  let val table = ThyData.get_records thy 
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
    48
  in
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
    49
    ThyData.put_records (Symtab.update ((name, info), table))
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
    50
  end;
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
    51
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
    52
local
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
    53
  fun record_infos thy None = []
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
    54
    | record_infos thy (Some info) =
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
    55
        case #parent info of 
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
    56
            None => [info]
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
    57
          | Some (_, parent) => record_infos thy (get_record thy parent) @ [info];
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
    58
  fun record_parass thy info = 
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
    59
    (map (map (fn (str, _) => (str, 0)) o #args) (record_infos thy (Some info))) 
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
    60
    : indexname list list; 
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
    61
  fun record_argss thy info = 
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
    62
    map (fst o the) (tl (map #parent (record_infos thy (Some info)))) @ 
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
    63
    [map TFree (#args info)];
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
    64
in  
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
    65
  fun record_field_names thy info = 
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
    66
    flat (map (map fst o #fields) (record_infos thy (Some info)));
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
    67
  fun record_field_types thy info = 
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
    68
    let 
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
    69
      val paras_args = map (op ~~) (record_parass thy info ~~ record_argss thy info);
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
    70
      val raw_substs = map typ_subst_TVars paras_args;
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
    71
      fun make_substs [] = []
4574
b922012cc142 error with instantiantion of sub-records removed
narasche
parents: 4564
diff changeset
    72
        | make_substs (x::xs) = (foldr1 (op o) (rev (x::xs))) :: make_substs xs; 
4454
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
    73
      val free_TFree = map (map (map_type_tfree (fn (str, s) => TVar((str, 0), s))));
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
    74
      val raw_record_field_types = map (map snd o #fields) (record_infos thy (Some info))
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
    75
    in 
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
    76
      flat (ListPair.map (fn (s, ts) => map s ts) 
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
    77
                         (make_substs raw_substs, free_TFree raw_record_field_types))
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
    78
    end;
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
    79
end;
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
    80
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
    81
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
    82
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
    83
(** abstract syntax **)
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
    84
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
    85
(* tuples *)
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
    86
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
    87
val unitT = Type ("unit",[]);
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
    88
val unit = Const ("()",unitT);
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
    89
fun mk_prodT (T1, T2) = Type ("*", [T1,T2]);
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
    90
fun mk_Pair (t1, t2) = 
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
    91
  let val T1 = fastype_of t1
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
    92
      and T2 = fastype_of t2
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
    93
  in Const ("Pair", [T1, T2] ---> mk_prodT (T1,T2)) $ t1 $ t2  end;
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
    94
4564
dc45cf21dbd2 Simplification: sel make and update make
narasche
parents: 4459
diff changeset
    95
val mk_eq = HOLogic.mk_Trueprop o HOLogic.mk_eq;
dc45cf21dbd2 Simplification: sel make and update make
narasche
parents: 4459
diff changeset
    96
4454
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
    97
fun dest_prodT (Type ("*", [T1, T2])) = (T1, T2)
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
    98
  | dest_prodT T = raise TYPE ("dest_prodT: product type expected", [T], []);
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
    99
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   100
fun mk_fst pT = Const ("fst", pT --> fst (dest_prodT pT));
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   101
fun mk_snd pT = Const ("snd", pT --> snd (dest_prodT pT));
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   102
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   103
fun ap_fst t = mk_fst (fastype_of t) $ t;
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   104
fun ap_snd t = mk_snd (fastype_of t) $ t;
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   105
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   106
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   107
(* records *)
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   108
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   109
fun selT T recT = recT --> T; 
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   110
fun updateT T recT = T --> recT --> recT;
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   111
val base_free = Free o apfst base;
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   112
val make_scheme_name = "make_scheme";
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   113
val make_name = "make";
4564
dc45cf21dbd2 Simplification: sel make and update make
narasche
parents: 4459
diff changeset
   114
fun def_suffix s = s ^ "_def";
dc45cf21dbd2 Simplification: sel make and update make
narasche
parents: 4459
diff changeset
   115
fun update_suffix s = s ^ "_update";
4454
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   116
fun make_schemeC full make_schemeT = Const (full make_scheme_name, make_schemeT);
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   117
fun makeC full makeT = Const (full make_name, makeT);
4564
dc45cf21dbd2 Simplification: sel make and update make
narasche
parents: 4459
diff changeset
   118
fun make_args_scheme full make_schemeT base_frees z = 
dc45cf21dbd2 Simplification: sel make and update make
narasche
parents: 4459
diff changeset
   119
  list_comb (make_schemeC full make_schemeT, base_frees) $ z;
dc45cf21dbd2 Simplification: sel make and update make
narasche
parents: 4459
diff changeset
   120
fun make_args full makeT base_frees = 
dc45cf21dbd2 Simplification: sel make and update make
narasche
parents: 4459
diff changeset
   121
  list_comb (makeC full makeT, base_frees); 
4454
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   122
fun selC s T recT = Const (s, selT T recT);
4564
dc45cf21dbd2 Simplification: sel make and update make
narasche
parents: 4459
diff changeset
   123
fun updateC s T recT = Const (update_suffix s, updateT T recT);
4454
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   124
fun frees xs = foldr add_typ_tfree_names (xs, []);
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   125
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   126
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   127
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   128
(** constants, definitions, axioms **)
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   129
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   130
(* constant declarations for make, selectors and update *)
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   131
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   132
fun decls make_schemeT makeT selT updateT recT current_fields =
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   133
  let val make_scheme_decl = (make_scheme_name, make_schemeT, NoSyn);
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   134
      val make_decl = (make_name, makeT, NoSyn);
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   135
      val sel_decls = map (fn (c, T) => (c, selT T recT, NoSyn)) current_fields;
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   136
      val update_decls = 
4564
dc45cf21dbd2 Simplification: sel make and update make
narasche
parents: 4459
diff changeset
   137
        map (fn (c, T) => (update_suffix c, updateT T recT, NoSyn)) current_fields
4454
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   138
  in 
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   139
    make_scheme_decl :: make_decl :: sel_decls @ update_decls
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   140
  end;
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   141
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   142
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   143
(* definitions for make, selectors and update *)
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   144
 
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   145
(*make*)
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   146
fun make_defs make_schemeT makeT base_frees z thy =
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   147
  let
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   148
    val sign = sign_of thy;
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   149
    val full = Sign.full_name sign;
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   150
    val make_scheme_def = 
4564
dc45cf21dbd2 Simplification: sel make and update make
narasche
parents: 4459
diff changeset
   151
      mk_defpair (make_args_scheme full make_schemeT base_frees z, 
dc45cf21dbd2 Simplification: sel make and update make
narasche
parents: 4459
diff changeset
   152
                  foldr mk_Pair (base_frees, z));
4454
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   153
    val make_def = 
4564
dc45cf21dbd2 Simplification: sel make and update make
narasche
parents: 4459
diff changeset
   154
      mk_defpair (make_args full makeT base_frees, 
dc45cf21dbd2 Simplification: sel make and update make
narasche
parents: 4459
diff changeset
   155
                  foldr mk_Pair (base_frees, unit))
4454
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   156
  in
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   157
    make_scheme_def :: [make_def]
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   158
  end;
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   159
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   160
(*selectors*)
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   161
fun sel_defs recT r all_fields current_fullfields = 
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   162
  let 
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   163
    val prefix_len = length all_fields  - length current_fullfields;
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   164
    val sel_terms = 
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   165
        map (fn k => ap_fst o funpow k ap_snd)
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   166
            (prefix_len upto length all_fields - 1)
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   167
  in
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   168
    ListPair.map 
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   169
      (fn ((s, T), t) => mk_defpair (selC s T recT $ r, t r)) 
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   170
      (current_fullfields, sel_terms)
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   171
  end;
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   172
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   173
(*update*)
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   174
fun update_defs recT r all_fields current_fullfields thy = 
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   175
  let
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   176
    val len_all_fields = length all_fields;
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   177
    fun sel_last r = funpow len_all_fields ap_snd r;
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   178
    fun update_def_s (s, T) = 
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   179
      let val updates = map (fn (s', T') => 
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   180
        if s = s' then base_free (s, T) else selC s' T' recT $ r)
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   181
        all_fields
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   182
      in
4564
dc45cf21dbd2 Simplification: sel make and update make
narasche
parents: 4459
diff changeset
   183
        mk_defpair (updateC s T recT $ base_free (s, T) $ r,
4454
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   184
                    foldr mk_Pair (updates, sel_last r)) 
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   185
      end;
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   186
  in 
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   187
    map update_def_s current_fullfields 
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   188
  end
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   189
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   190
4564
dc45cf21dbd2 Simplification: sel make and update make
narasche
parents: 4459
diff changeset
   191
(* theorems for make, selectors and update *)
dc45cf21dbd2 Simplification: sel make and update make
narasche
parents: 4459
diff changeset
   192
 
dc45cf21dbd2 Simplification: sel make and update make
narasche
parents: 4459
diff changeset
   193
(*preparations*)
dc45cf21dbd2 Simplification: sel make and update make
narasche
parents: 4459
diff changeset
   194
fun get_all_selector_defs all_fields full thy = 
dc45cf21dbd2 Simplification: sel make and update make
narasche
parents: 4459
diff changeset
   195
  map (fn (s, T) => get_axiom thy (def_suffix s)) all_fields; 
dc45cf21dbd2 Simplification: sel make and update make
narasche
parents: 4459
diff changeset
   196
fun get_all_update_defs all_fields full thy = 
dc45cf21dbd2 Simplification: sel make and update make
narasche
parents: 4459
diff changeset
   197
  map (fn (s, T) => get_axiom thy (def_suffix (update_suffix s))) all_fields;
dc45cf21dbd2 Simplification: sel make and update make
narasche
parents: 4459
diff changeset
   198
fun get_make_scheme_def full thy = get_axiom thy (full (def_suffix make_scheme_name));
dc45cf21dbd2 Simplification: sel make and update make
narasche
parents: 4459
diff changeset
   199
fun get_make_def full thy = get_axiom thy (full (def_suffix make_name));
dc45cf21dbd2 Simplification: sel make and update make
narasche
parents: 4459
diff changeset
   200
fun all_rec_defs all_fields full thy = 
dc45cf21dbd2 Simplification: sel make and update make
narasche
parents: 4459
diff changeset
   201
  get_make_scheme_def full thy :: get_make_def full thy :: 
dc45cf21dbd2 Simplification: sel make and update make
narasche
parents: 4459
diff changeset
   202
  get_all_selector_defs all_fields full thy @ get_all_update_defs all_fields full thy; 
dc45cf21dbd2 Simplification: sel make and update make
narasche
parents: 4459
diff changeset
   203
fun prove_goal_s goal_s all_fields full thy = 
dc45cf21dbd2 Simplification: sel make and update make
narasche
parents: 4459
diff changeset
   204
  map (fn (s,T) => 
dc45cf21dbd2 Simplification: sel make and update make
narasche
parents: 4459
diff changeset
   205
         (prove_goalw_cterm (all_rec_defs all_fields full thy) 
dc45cf21dbd2 Simplification: sel make and update make
narasche
parents: 4459
diff changeset
   206
                            (cterm_of (sign_of thy) (mk_eq (goal_s (s,T))))
dc45cf21dbd2 Simplification: sel make and update make
narasche
parents: 4459
diff changeset
   207
                            (K [simp_tac (HOL_basic_ss addsimps [fst_conv,snd_conv]) 1])))
dc45cf21dbd2 Simplification: sel make and update make
narasche
parents: 4459
diff changeset
   208
      all_fields;
dc45cf21dbd2 Simplification: sel make and update make
narasche
parents: 4459
diff changeset
   209
dc45cf21dbd2 Simplification: sel make and update make
narasche
parents: 4459
diff changeset
   210
(*si (make(_scheme) x1 ... xi ... xn) = xi*)
dc45cf21dbd2 Simplification: sel make and update make
narasche
parents: 4459
diff changeset
   211
fun sel_make_scheme_thms recT make_schemeT base_frees z all_fields full thy = 
dc45cf21dbd2 Simplification: sel make and update make
narasche
parents: 4459
diff changeset
   212
  let     
dc45cf21dbd2 Simplification: sel make and update make
narasche
parents: 4459
diff changeset
   213
    fun sel_make_scheme_s (s, T) = 
dc45cf21dbd2 Simplification: sel make and update make
narasche
parents: 4459
diff changeset
   214
        (selC s T recT $ make_args_scheme full make_schemeT base_frees z, base_free(s,T)) 
dc45cf21dbd2 Simplification: sel make and update make
narasche
parents: 4459
diff changeset
   215
  in
dc45cf21dbd2 Simplification: sel make and update make
narasche
parents: 4459
diff changeset
   216
    prove_goal_s sel_make_scheme_s all_fields full thy
dc45cf21dbd2 Simplification: sel make and update make
narasche
parents: 4459
diff changeset
   217
  end;
dc45cf21dbd2 Simplification: sel make and update make
narasche
parents: 4459
diff changeset
   218
dc45cf21dbd2 Simplification: sel make and update make
narasche
parents: 4459
diff changeset
   219
fun sel_make_thms recT_unitT makeT base_frees all_fields full thy = 
dc45cf21dbd2 Simplification: sel make and update make
narasche
parents: 4459
diff changeset
   220
  let     
dc45cf21dbd2 Simplification: sel make and update make
narasche
parents: 4459
diff changeset
   221
    fun sel_make_s (s, T) = 
dc45cf21dbd2 Simplification: sel make and update make
narasche
parents: 4459
diff changeset
   222
        (selC s T recT_unitT $ make_args full makeT base_frees, Free(base s,T)) 
dc45cf21dbd2 Simplification: sel make and update make
narasche
parents: 4459
diff changeset
   223
  in
dc45cf21dbd2 Simplification: sel make and update make
narasche
parents: 4459
diff changeset
   224
    prove_goal_s sel_make_s all_fields full thy
dc45cf21dbd2 Simplification: sel make and update make
narasche
parents: 4459
diff changeset
   225
  end;
dc45cf21dbd2 Simplification: sel make and update make
narasche
parents: 4459
diff changeset
   226
dc45cf21dbd2 Simplification: sel make and update make
narasche
parents: 4459
diff changeset
   227
(*si_update xia (make(_scheme) x1 ... xi ... xn) = (make x1 ... xia ... xn)*)
dc45cf21dbd2 Simplification: sel make and update make
narasche
parents: 4459
diff changeset
   228
fun update_make_scheme_thms recT make_schemeT base_frees z all_fields full thy = 
dc45cf21dbd2 Simplification: sel make and update make
narasche
parents: 4459
diff changeset
   229
  let 
dc45cf21dbd2 Simplification: sel make and update make
narasche
parents: 4459
diff changeset
   230
    fun update_make_scheme_s (s, T) = 
dc45cf21dbd2 Simplification: sel make and update make
narasche
parents: 4459
diff changeset
   231
     (updateC s T recT $ base_free(s ^ "'", T) $ 
dc45cf21dbd2 Simplification: sel make and update make
narasche
parents: 4459
diff changeset
   232
        make_args_scheme full make_schemeT base_frees z, 
dc45cf21dbd2 Simplification: sel make and update make
narasche
parents: 4459
diff changeset
   233
      make_args_scheme full make_schemeT 
dc45cf21dbd2 Simplification: sel make and update make
narasche
parents: 4459
diff changeset
   234
        (map (fn t => if t = base_free(s, T) then base_free(s ^ "'", T) else t) base_frees) z)
dc45cf21dbd2 Simplification: sel make and update make
narasche
parents: 4459
diff changeset
   235
  in 
dc45cf21dbd2 Simplification: sel make and update make
narasche
parents: 4459
diff changeset
   236
    prove_goal_s update_make_scheme_s all_fields full thy
dc45cf21dbd2 Simplification: sel make and update make
narasche
parents: 4459
diff changeset
   237
  end;
dc45cf21dbd2 Simplification: sel make and update make
narasche
parents: 4459
diff changeset
   238
dc45cf21dbd2 Simplification: sel make and update make
narasche
parents: 4459
diff changeset
   239
fun update_make_thms recT_unitT makeT base_frees all_fields full thy = 
dc45cf21dbd2 Simplification: sel make and update make
narasche
parents: 4459
diff changeset
   240
  let 
dc45cf21dbd2 Simplification: sel make and update make
narasche
parents: 4459
diff changeset
   241
    fun update_make_s (s, T) = 
dc45cf21dbd2 Simplification: sel make and update make
narasche
parents: 4459
diff changeset
   242
     (updateC s T recT_unitT $ base_free(s ^ "'", T) $ 
dc45cf21dbd2 Simplification: sel make and update make
narasche
parents: 4459
diff changeset
   243
        make_args full makeT base_frees, 
dc45cf21dbd2 Simplification: sel make and update make
narasche
parents: 4459
diff changeset
   244
      make_args full makeT 
dc45cf21dbd2 Simplification: sel make and update make
narasche
parents: 4459
diff changeset
   245
        (map (fn t => if t = base_free(s, T) then base_free(s ^ "'", T) else t) base_frees))
dc45cf21dbd2 Simplification: sel make and update make
narasche
parents: 4459
diff changeset
   246
  in 
dc45cf21dbd2 Simplification: sel make and update make
narasche
parents: 4459
diff changeset
   247
    prove_goal_s update_make_s all_fields full thy
dc45cf21dbd2 Simplification: sel make and update make
narasche
parents: 4459
diff changeset
   248
  end;
dc45cf21dbd2 Simplification: sel make and update make
narasche
parents: 4459
diff changeset
   249
dc45cf21dbd2 Simplification: sel make and update make
narasche
parents: 4459
diff changeset
   250
4454
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   251
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   252
(** errors **)
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   253
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   254
fun check_duplicate_fields all_field_names =
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   255
  let val has_dupl = findrep all_field_names
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   256
  in
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   257
    if null has_dupl then []
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   258
      else ["Duplicate field declaration: " ^ quote (hd has_dupl) ^
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   259
            " (Double might be in ancestor)"]
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   260
  end;
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   261
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   262
fun check_parent None name thy = []
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   263
  | check_parent (Some (args, parent)) name thy = 
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   264
     let 
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   265
       val opt_info = get_record thy parent;
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   266
       val sign = sign_of thy;
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   267
       fun check_sorts [] [] = []
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   268
         | check_sorts ((str, sort)::xs) (y::ys) = 
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   269
            if of_sort sign (y, sort)
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   270
              then check_sorts xs ys 
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   271
              else ["Sort of " ^ 
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   272
                    quote (Pretty.string_of (Sign.pretty_typ sign y)) ^ 
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   273
                    " does not match parent declaration"] 
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   274
     in 
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   275
       case opt_info of 
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   276
         None => ["Parent " ^ quote parent ^" not defined"]
4459
4066db36616b records without signature
narasche
parents: 4454
diff changeset
   277
       | Some {args = pargs, parent = pparent, fields = pfields} =>
4454
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   278
           if (length args = length pargs) 
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   279
             then check_sorts pargs args
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   280
             else ["Mismatching arities for parent " ^ quote (base parent)] 
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   281
     end;    
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   282
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   283
fun check_duplicate_records thy full_name =
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   284
  if is_none (get_record thy full_name) then [] 
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   285
    else ["Duplicate record declaration"];
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   286
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   287
fun check_duplicate_args raw_args =
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   288
  let val has_dupl = findrep raw_args
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   289
  in
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   290
    if null has_dupl then []
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   291
      else ["Duplicate parameter: " ^ quote (hd has_dupl)]
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   292
  end;
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   293
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   294
fun check_raw_args raw_args free_vars thy = 
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   295
  let
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   296
    val free_vars_names = map fst free_vars;
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   297
    val diff_set = set_minus free_vars_names raw_args;
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   298
    val default_sort =  Type.defaultS ((#tsig o Sign.rep_sg) (sign_of thy));
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   299
    val assign_sorts = 
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   300
      map (fn x => case assoc (free_vars, x) of
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   301
                     None => (x, default_sort)
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   302
                   | Some sort => (x, sort)) raw_args
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   303
  in
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   304
    if free_vars_names subset raw_args 
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   305
      then ([], assign_sorts)
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   306
      else (["Free type variable(s): " ^ 
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   307
               (foldr1 (fn (s, s') => s ^ ", " ^ s') (map quote diff_set))],
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   308
            []) 
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   309
  end;
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   310
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   311
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   312
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   313
(** ext_record **)
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   314
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   315
fun ext_record (args, name) opt_parent current_fields thy =
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   316
  let
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   317
    val full_name = Sign.full_name (sign_of thy) name;
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   318
    val thy = thy |> Theory.add_path name;
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   319
    val sign = sign_of thy;
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   320
    val full = Sign.full_name sign;
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   321
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   322
    val current_fullfields = map (apfst full) current_fields;
4459
4066db36616b records without signature
narasche
parents: 4454
diff changeset
   323
    val info = {args = args, fields = current_fullfields, parent = opt_parent};
4454
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   324
    val thy = thy |> put_record thy full_name info;
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   325
    val all_types = record_field_types thy info; 
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   326
    val all_fields = record_field_names thy info ~~ all_types;
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   327
    val base_frees = map base_free all_fields;
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   328
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   329
    val tfrees = frees all_types;
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   330
    val zeta = variant tfrees "'z";
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   331
    val zetaT = TFree (zeta, HOLogic.termS); 
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   332
    val z = base_free ("z", zetaT);
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   333
    val recT = foldr mk_prodT (all_types, zetaT);
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   334
    val recT_unitT = foldr mk_prodT (all_types, unitT);
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   335
    val make_schemeT = (all_types @ [zetaT]) ---> recT;
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   336
    val makeT = all_types ---> recT_unitT;
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   337
    val r = base_free ("r", recT);
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   338
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   339
    val errors = check_duplicate_fields (map base (record_field_names thy info))
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   340
  in
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   341
    if not (null errors) 
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   342
      then error (cat_lines errors) else 
4564
dc45cf21dbd2 Simplification: sel make and update make
narasche
parents: 4459
diff changeset
   343
      let val thy = 
4454
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   344
        thy |> Theory.add_path ".."
4564
dc45cf21dbd2 Simplification: sel make and update make
narasche
parents: 4459
diff changeset
   345
            |> Theory.add_tyabbrs_i [(name ^ "_scheme", tfrees @ [zeta], recT, NoSyn)]  
dc45cf21dbd2 Simplification: sel make and update make
narasche
parents: 4459
diff changeset
   346
            |> Theory.add_tyabbrs_i [(name, tfrees, recT_unitT, NoSyn)]  
4454
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   347
            |> Theory.add_path name
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   348
            |> Theory.add_consts_i (decls make_schemeT makeT selT updateT recT current_fields)
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   349
            |> Theory.add_defs_i 
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   350
                  ((make_defs make_schemeT makeT base_frees z thy) @ 
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   351
                   (sel_defs recT r all_fields current_fullfields) @
4574
b922012cc142 error with instantiantion of sub-records removed
narasche
parents: 4564
diff changeset
   352
                   (update_defs recT r all_fields current_fullfields thy)) 
4564
dc45cf21dbd2 Simplification: sel make and update make
narasche
parents: 4459
diff changeset
   353
      in 
dc45cf21dbd2 Simplification: sel make and update make
narasche
parents: 4459
diff changeset
   354
        thy |> PureThy.store_thmss 
dc45cf21dbd2 Simplification: sel make and update make
narasche
parents: 4459
diff changeset
   355
                 [("record_simps", 
dc45cf21dbd2 Simplification: sel make and update make
narasche
parents: 4459
diff changeset
   356
                   sel_make_scheme_thms recT make_schemeT base_frees z all_fields full thy @  
dc45cf21dbd2 Simplification: sel make and update make
narasche
parents: 4459
diff changeset
   357
                   sel_make_thms recT_unitT makeT base_frees all_fields full thy @
dc45cf21dbd2 Simplification: sel make and update make
narasche
parents: 4459
diff changeset
   358
                   update_make_scheme_thms recT make_schemeT base_frees z all_fields full thy @
4574
b922012cc142 error with instantiantion of sub-records removed
narasche
parents: 4564
diff changeset
   359
                   update_make_thms recT_unitT makeT base_frees all_fields full thy )]
4454
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   360
            |> Theory.add_path ".." 
4564
dc45cf21dbd2 Simplification: sel make and update make
narasche
parents: 4459
diff changeset
   361
      end
dc45cf21dbd2 Simplification: sel make and update make
narasche
parents: 4459
diff changeset
   362
dc45cf21dbd2 Simplification: sel make and update make
narasche
parents: 4459
diff changeset
   363
(* @ update_make_thms @ 
dc45cf21dbd2 Simplification: sel make and update make
narasche
parents: 4459
diff changeset
   364
                     update_update_thms @ sel_update_thms)]  *)
dc45cf21dbd2 Simplification: sel make and update make
narasche
parents: 4459
diff changeset
   365
4454
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   366
  end;
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   367
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   368
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   369
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   370
(** external interfaces **)
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   371
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   372
(* add_record *)
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   373
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   374
fun add_record_aux prep_typ prep_parent (raw_args, name) raw_parent raw_fields thy =
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   375
  let
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   376
    val _ = require_thy thy "Prod" "record definitions";
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   377
    val sign = sign_of thy;
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   378
    val full_name = Sign.full_name sign name;
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   379
    val make_assocs = map (fn (a, b) => ((a, ~1), b));
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   380
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   381
    val parent = apsome (prep_parent sign) raw_parent;
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   382
    val parent_args = if_none (apsome fst parent) [];
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   383
    val parent_assoc = make_assocs (foldr (op union) ((map typ_tfrees parent_args), []));
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   384
 
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   385
    fun prepare_fields ass [] = []
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   386
      | prepare_fields ass ((name, str)::xs) = 
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   387
         let val type_of_name = prep_typ sign ass str
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   388
         in (name, type_of_name)::
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   389
              (prepare_fields (ass union (make_assocs (typ_tfrees type_of_name))) xs)
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   390
         end;
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   391
    val fields = prepare_fields (parent_assoc) raw_fields;
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   392
    val fields_types = map snd fields;
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   393
    val free_vars = foldr (op union) ((map typ_tfrees fields_types), []);
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   394
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   395
    val check_args = check_raw_args raw_args free_vars thy;
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   396
    val args = snd check_args;
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   397
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   398
    val errors = (check_parent parent name thy) @ 
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   399
                 (check_duplicate_records thy full_name) @
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   400
                 (check_duplicate_args raw_args) @
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   401
                 (fst check_args)
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   402
  in 
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   403
    if not (null errors) 
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   404
      then error (cat_lines errors)
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   405
      else ext_record (args, name) parent fields thy 
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   406
  end
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   407
  handle ERROR =>
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   408
    error ("The error(s) above occurred in record declaration " ^ quote name);
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   409
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   410
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   411
(* internalization methods *)
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   412
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   413
fun read_parent sign name =
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   414
  (case Sign.read_raw_typ (sign, K None) name of
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   415
    Type (name, Ts) => (Ts, name)
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   416
  | _ => error ("Malformed parent specification: " ^ name));
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   417
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   418
fun read_typ sign ass name = 
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   419
  Sign.read_typ (sign, curry assoc ass) name handle TYPE (msg, _, _) => error msg;
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   420
 
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   421
fun cert_typ sign ass T =
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   422
  Sign.certify_typ sign T handle TYPE (msg, _, _) => error msg;
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   423
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   424
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   425
(* add_record(_i) *)
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   426
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   427
val add_record = add_record_aux read_typ read_parent;
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   428
val add_record_i = add_record_aux cert_typ (K I);
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   429
2e089fae6ed7 first version of records
narasche
parents:
diff changeset
   430
end;