src/HOL/Tools/recdef_package.ML
author wenzelm
Tue, 05 Sep 2000 18:49:26 +0200
changeset 9859 2cd338998b53
parent 9652 ea1f02d6d65b
child 9876 a069795f1060
permissions -rw-r--r--
recdef hints (attributes and modifiers);
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6429
9771ce553e56 Wrapper module for Konrad Slind's TFL package.
wenzelm
parents:
diff changeset
     1
(*  Title:      HOL/Tools/recdef_package.ML
9771ce553e56 Wrapper module for Konrad Slind's TFL package.
wenzelm
parents:
diff changeset
     2
    ID:         $Id$
9771ce553e56 Wrapper module for Konrad Slind's TFL package.
wenzelm
parents:
diff changeset
     3
    Author:     Markus Wenzel, TU Muenchen
9771ce553e56 Wrapper module for Konrad Slind's TFL package.
wenzelm
parents:
diff changeset
     4
9771ce553e56 Wrapper module for Konrad Slind's TFL package.
wenzelm
parents:
diff changeset
     5
Wrapper module for Konrad Slind's TFL package.
9771ce553e56 Wrapper module for Konrad Slind's TFL package.
wenzelm
parents:
diff changeset
     6
*)
9771ce553e56 Wrapper module for Konrad Slind's TFL package.
wenzelm
parents:
diff changeset
     7
9771ce553e56 Wrapper module for Konrad Slind's TFL package.
wenzelm
parents:
diff changeset
     8
signature RECDEF_PACKAGE =
9771ce553e56 Wrapper module for Konrad Slind's TFL package.
wenzelm
parents:
diff changeset
     9
sig
9771ce553e56 Wrapper module for Konrad Slind's TFL package.
wenzelm
parents:
diff changeset
    10
  val quiet_mode: bool ref
6439
7eea9f25dc49 'HOL/recdef' theory data;
wenzelm
parents: 6429
diff changeset
    11
  val print_recdefs: theory -> unit
8657
b9475dad85ed recdef: admit names/atts;
wenzelm
parents: 8625
diff changeset
    12
  val get_recdef: theory -> string
b9475dad85ed recdef: admit names/atts;
wenzelm
parents: 8625
diff changeset
    13
    -> {simps: thm list, rules: thm list list, induct: thm, tcs: term list} option
9859
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    14
  val simp_add_global: theory attribute
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    15
  val simp_del_global: theory attribute
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    16
  val cong_add_global: theory attribute
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    17
  val cong_del_global: theory attribute
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    18
  val wf_add_global: theory attribute
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    19
  val wf_del_global: theory attribute
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    20
  val simp_add_local: Proof.context attribute
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    21
  val simp_del_local: Proof.context attribute
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    22
  val cong_add_local: Proof.context attribute
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    23
  val cong_del_local: Proof.context attribute
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    24
  val wf_add_local: Proof.context attribute
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    25
  val wf_del_local: Proof.context attribute
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    26
  val add_recdef: xstring -> string -> ((bstring * string) * Args.src list) list ->
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    27
    Args.src option -> theory -> theory
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    28
      * {simps: thm list, rules: thm list list, induct: thm, tcs: term list}
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    29
  val add_recdef_i: xstring -> term -> ((bstring * term) * theory attribute list) list ->
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    30
    theory -> theory * {simps: thm list, rules: thm list list, induct: thm, tcs: term list}
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    31
  val add_recdef_old: xstring -> string -> ((bstring * string) * Args.src list) list ->
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    32
    simpset * thm list -> theory ->
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    33
    theory * {simps: thm list, rules: thm list list, induct: thm, tcs: term list}
6557
d7e7532c128a peoper defer_recdef interface;
wenzelm
parents: 6520
diff changeset
    34
  val defer_recdef: xstring -> string list -> (xstring * Args.src list) list
d7e7532c128a peoper defer_recdef interface;
wenzelm
parents: 6520
diff changeset
    35
    -> theory -> theory * {induct_rules: thm}
d7e7532c128a peoper defer_recdef interface;
wenzelm
parents: 6520
diff changeset
    36
  val defer_recdef_i: xstring -> term list -> (thm * theory attribute list) list
d7e7532c128a peoper defer_recdef interface;
wenzelm
parents: 6520
diff changeset
    37
    -> theory -> theory * {induct_rules: thm}
6439
7eea9f25dc49 'HOL/recdef' theory data;
wenzelm
parents: 6429
diff changeset
    38
  val setup: (theory -> theory) list
6429
9771ce553e56 Wrapper module for Konrad Slind's TFL package.
wenzelm
parents:
diff changeset
    39
end;
9771ce553e56 Wrapper module for Konrad Slind's TFL package.
wenzelm
parents:
diff changeset
    40
9771ce553e56 Wrapper module for Konrad Slind's TFL package.
wenzelm
parents:
diff changeset
    41
structure RecdefPackage: RECDEF_PACKAGE =
9771ce553e56 Wrapper module for Konrad Slind's TFL package.
wenzelm
parents:
diff changeset
    42
struct
9771ce553e56 Wrapper module for Konrad Slind's TFL package.
wenzelm
parents:
diff changeset
    43
9859
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    44
6429
9771ce553e56 Wrapper module for Konrad Slind's TFL package.
wenzelm
parents:
diff changeset
    45
val quiet_mode = Tfl.quiet_mode;
9771ce553e56 Wrapper module for Konrad Slind's TFL package.
wenzelm
parents:
diff changeset
    46
val message = Tfl.message;
9771ce553e56 Wrapper module for Konrad Slind's TFL package.
wenzelm
parents:
diff changeset
    47
9771ce553e56 Wrapper module for Konrad Slind's TFL package.
wenzelm
parents:
diff changeset
    48
9859
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    49
(** recdef hints **)
6439
7eea9f25dc49 'HOL/recdef' theory data;
wenzelm
parents: 6429
diff changeset
    50
9859
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    51
(* type hints *)
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    52
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    53
type hints = {simps: thm list, congs: (string * thm) list, wfs: thm list};
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    54
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    55
fun mk_hints (simps, congs, wfs) = {simps = simps, congs = congs, wfs = wfs}: hints;
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    56
fun map_hints f ({simps, congs, wfs}: hints) = mk_hints (f (simps, congs, wfs));
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    57
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    58
fun map_simps f = map_hints (fn (simps, congs, wfs) => (f simps, congs, wfs));
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    59
fun map_congs f = map_hints (fn (simps, congs, wfs) => (simps, f congs, wfs));
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    60
fun map_wfs f = map_hints (fn (simps, congs, wfs) => (simps, congs, f wfs));
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    61
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    62
fun pretty_hints ({simps, congs, wfs}: hints) =
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    63
 [Pretty.big_list "recdef simp hints:" (map Display.pretty_thm simps),
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    64
  Pretty.big_list "recdef cong hints:" (map Display.pretty_thm (map #2 congs)),
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    65
  Pretty.big_list "recdef wf hints:" (map Display.pretty_thm wfs)];
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    66
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    67
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    68
(* congruence rules *)
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    69
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    70
local
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    71
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    72
val cong_head =
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    73
  fst o Term.dest_Const o Term.head_of o fst o Logic.dest_equals o Thm.concl_of;
6439
7eea9f25dc49 'HOL/recdef' theory data;
wenzelm
parents: 6429
diff changeset
    74
9859
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    75
fun prep_cong raw_thm =
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    76
  let val thm = safe_mk_meta_eq raw_thm in (cong_head thm, thm) end;
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    77
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    78
in
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    79
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    80
fun add_cong raw_thm congs =
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    81
  let val (c, thm) = prep_cong raw_thm
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    82
  in overwrite_warn (congs, (c, thm)) ("Overwriting recdef congruence rule for " ^ quote c) end;
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    83
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    84
fun del_cong raw_thm congs =
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    85
  let
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    86
    val (c, thm) = prep_cong raw_thm;
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    87
    val (del, rest) = Library.partition (Library.equal c o fst) congs;
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    88
  in if null del then (warning ("No recdef congruence rule for " ^ quote c); congs) else rest end;
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    89
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    90
val add_congs = curry (foldr (uncurry add_cong));
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    91
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    92
end;
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    93
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    94
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    95
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    96
(** global and local recdef data **)
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    97
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    98
(* theory data kind 'HOL/recdef' *)
6439
7eea9f25dc49 'HOL/recdef' theory data;
wenzelm
parents: 6429
diff changeset
    99
8657
b9475dad85ed recdef: admit names/atts;
wenzelm
parents: 8625
diff changeset
   100
type recdef_info = {simps: thm list, rules: thm list list, induct: thm, tcs: term list};
6439
7eea9f25dc49 'HOL/recdef' theory data;
wenzelm
parents: 6429
diff changeset
   101
9859
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   102
structure GlobalRecdefArgs =
6439
7eea9f25dc49 'HOL/recdef' theory data;
wenzelm
parents: 6429
diff changeset
   103
struct
7eea9f25dc49 'HOL/recdef' theory data;
wenzelm
parents: 6429
diff changeset
   104
  val name = "HOL/recdef";
9859
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   105
  type T = recdef_info Symtab.table * hints;
6439
7eea9f25dc49 'HOL/recdef' theory data;
wenzelm
parents: 6429
diff changeset
   106
9859
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   107
  val empty = (Symtab.empty, mk_hints ([], [], []));
6557
d7e7532c128a peoper defer_recdef interface;
wenzelm
parents: 6520
diff changeset
   108
  val copy = I;
6439
7eea9f25dc49 'HOL/recdef' theory data;
wenzelm
parents: 6429
diff changeset
   109
  val prep_ext = I;
9859
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   110
  fun merge
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   111
   ((tab1, {simps = simps1, congs = congs1, wfs = wfs1}),
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   112
    (tab2, {simps = simps2, congs = congs2, wfs = wfs2})) =
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   113
      (Symtab.merge (K true) (tab1, tab2),
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   114
        mk_hints (Drule.merge_rules (simps1, simps2),
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   115
          Library.merge_alists congs1 congs2,
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   116
          Drule.merge_rules (wfs1, wfs2)));
6439
7eea9f25dc49 'HOL/recdef' theory data;
wenzelm
parents: 6429
diff changeset
   117
9859
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   118
  fun print sg (tab, hints) =
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   119
   (Pretty.strs ("recdefs:" :: map #1 (Sign.cond_extern_table sg Sign.constK tab)) ::
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   120
     pretty_hints hints) |> Pretty.chunks |> Pretty.writeln;
6439
7eea9f25dc49 'HOL/recdef' theory data;
wenzelm
parents: 6429
diff changeset
   121
end;
7eea9f25dc49 'HOL/recdef' theory data;
wenzelm
parents: 6429
diff changeset
   122
9859
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   123
structure GlobalRecdefData = TheoryDataFun(GlobalRecdefArgs);
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   124
val print_recdefs = GlobalRecdefData.print;
6429
9771ce553e56 Wrapper module for Konrad Slind's TFL package.
wenzelm
parents:
diff changeset
   125
6439
7eea9f25dc49 'HOL/recdef' theory data;
wenzelm
parents: 6429
diff changeset
   126
9859
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   127
fun get_recdef thy name = Symtab.lookup (#1 (GlobalRecdefData.get thy), name);
6439
7eea9f25dc49 'HOL/recdef' theory data;
wenzelm
parents: 6429
diff changeset
   128
7eea9f25dc49 'HOL/recdef' theory data;
wenzelm
parents: 6429
diff changeset
   129
fun put_recdef name info thy =
6429
9771ce553e56 Wrapper module for Konrad Slind's TFL package.
wenzelm
parents:
diff changeset
   130
  let
9859
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   131
    val (tab, hints) = GlobalRecdefData.get thy;
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   132
    val tab' = Symtab.update_new ((name, info), tab)
6439
7eea9f25dc49 'HOL/recdef' theory data;
wenzelm
parents: 6429
diff changeset
   133
      handle Symtab.DUP _ => error ("Duplicate recursive function definition " ^ quote name);
9859
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   134
  in GlobalRecdefData.put (tab', hints) thy end;
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   135
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   136
val get_global_hints = #2 o GlobalRecdefData.get;
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   137
val map_global_hints = GlobalRecdefData.map o apsnd;
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   138
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   139
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   140
(* proof data kind 'HOL/recdef' *)
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   141
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   142
structure LocalRecdefArgs =
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   143
struct
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   144
  val name = "HOL/recdef";
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   145
  type T = hints;
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   146
  val init = get_global_hints;
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   147
  fun print _ hints = pretty_hints hints |> Pretty.chunks |> Pretty.writeln;
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   148
end;
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   149
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   150
structure LocalRecdefData = ProofDataFun(LocalRecdefArgs);
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   151
val get_local_hints = LocalRecdefData.get;
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   152
val map_local_hints = LocalRecdefData.map;
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   153
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   154
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   155
(* attributes *)
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   156
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   157
local
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   158
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   159
fun global_local f g =
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   160
 (fn (thy, thm) => (map_global_hints (f (g thm)) thy, thm),
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   161
  fn (ctxt, thm) => (map_local_hints (f (g thm)) ctxt, thm));
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   162
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   163
fun mk_attr (add1, add2) (del1, del2) =
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   164
 (Attrib.add_del_args add1 del1, Attrib.add_del_args add2 del2);
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   165
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   166
in
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   167
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   168
val (simp_add_global, simp_add_local) = global_local map_simps (Drule.add_rules o single);
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   169
val (simp_del_global, simp_del_local) = global_local map_simps (Drule.del_rules o single);
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   170
val (cong_add_global, cong_add_local) = global_local map_congs add_cong;
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   171
val (cong_del_global, cong_del_local) = global_local map_congs del_cong;
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   172
val (wf_add_global, wf_add_local) = global_local map_wfs (Drule.add_rules o single);
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   173
val (wf_del_global, wf_del_local) = global_local map_wfs (Drule.del_rules o single);
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   174
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   175
val simp_attr = mk_attr (simp_add_global, simp_add_local) (simp_del_global, simp_del_local);
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   176
val cong_attr = mk_attr (cong_add_global, cong_add_local) (cong_del_global, cong_del_local);
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   177
val wf_attr = mk_attr (wf_add_global, wf_add_local) (wf_del_global, wf_del_local);
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   178
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   179
end;
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   180
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   181
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   182
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   183
(** prepare_hints(_i) **)
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   184
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   185
local
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   186
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   187
val simpN = "simp";
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   188
val congN = "cong";
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   189
val wfN = "wf";
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   190
val addN = "add";
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   191
val delN = "del";
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   192
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   193
val recdef_modifiers =
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   194
 [Args.$$$ simpN -- Args.colon >> K ((I, simp_add_local): Method.modifier),
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   195
  Args.$$$ simpN -- Args.$$$ addN -- Args.colon >> K (I, simp_add_local),
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   196
  Args.$$$ simpN -- Args.$$$ delN -- Args.colon >> K (I, simp_del_local),
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   197
  Args.$$$ congN -- Args.colon >> K (I, cong_add_local),
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   198
  Args.$$$ congN -- Args.$$$ addN -- Args.colon >> K (I, cong_add_local),
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   199
  Args.$$$ congN -- Args.$$$ delN -- Args.colon >> K (I, cong_del_local),
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   200
  Args.$$$ wfN -- Args.colon >> K (I, wf_add_local),
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   201
  Args.$$$ wfN -- Args.$$$ addN -- Args.colon >> K (I, wf_add_local),
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   202
  Args.$$$ wfN -- Args.$$$ delN -- Args.colon >> K (I, wf_del_local)];
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   203
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   204
val modifiers =  (* FIXME include 'simp cong' (!?) *)
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   205
  recdef_modifiers @ Splitter.split_modifiers @ Classical.cla_modifiers @ Clasimp.iff_modifiers;
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   206
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   207
in
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   208
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   209
fun prepare_hints thy opt_src =
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   210
  let
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   211
    val ctxt0 = ProofContext.init thy;
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   212
    val ctxt =
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   213
      (case opt_src of
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   214
        None => ctxt0
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   215
      | Some src => Method.only_sectioned_args modifiers I src ctxt0);
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   216
    val {simps, congs, wfs} = get_local_hints ctxt;
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   217
    val cs = Classical.get_local_claset ctxt;
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   218
    val ss = Simplifier.get_local_simpset ctxt addsimps simps;
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   219
  in (cs, ss, map #2 congs, wfs) end;
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   220
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   221
fun prepare_hints_i thy () =
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   222
  let val {simps, congs, wfs} = get_global_hints thy
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   223
  in (Classical.claset_of thy, Simplifier.simpset_of thy addsimps simps, map #2 congs, wfs) end;
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   224
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   225
end;
6439
7eea9f25dc49 'HOL/recdef' theory data;
wenzelm
parents: 6429
diff changeset
   226
7eea9f25dc49 'HOL/recdef' theory data;
wenzelm
parents: 6429
diff changeset
   227
7eea9f25dc49 'HOL/recdef' theory data;
wenzelm
parents: 6429
diff changeset
   228
7eea9f25dc49 'HOL/recdef' theory data;
wenzelm
parents: 6429
diff changeset
   229
(** add_recdef(_i) **)
7eea9f25dc49 'HOL/recdef' theory data;
wenzelm
parents: 6429
diff changeset
   230
6557
d7e7532c128a peoper defer_recdef interface;
wenzelm
parents: 6520
diff changeset
   231
fun requires_recdef thy = Theory.requires thy "Recdef" "recursive functions";
d7e7532c128a peoper defer_recdef interface;
wenzelm
parents: 6520
diff changeset
   232
9859
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   233
fun gen_add_recdef tfl_fn prep_att prep_hints raw_name R eq_srcs hints thy =
6439
7eea9f25dc49 'HOL/recdef' theory data;
wenzelm
parents: 6429
diff changeset
   234
  let
9859
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   235
    val _ = requires_recdef thy;
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   236
6439
7eea9f25dc49 'HOL/recdef' theory data;
wenzelm
parents: 6429
diff changeset
   237
    val name = Sign.intern_const (Theory.sign_of thy) raw_name;
7eea9f25dc49 'HOL/recdef' theory data;
wenzelm
parents: 6429
diff changeset
   238
    val bname = Sign.base_name name;
6429
9771ce553e56 Wrapper module for Konrad Slind's TFL package.
wenzelm
parents:
diff changeset
   239
    val _ = message ("Defining recursive function " ^ quote name ^ " ...");
9771ce553e56 Wrapper module for Konrad Slind's TFL package.
wenzelm
parents:
diff changeset
   240
8657
b9475dad85ed recdef: admit names/atts;
wenzelm
parents: 8625
diff changeset
   241
    val ((eq_names, eqs), raw_eq_atts) = apfst split_list (split_list eq_srcs);
b9475dad85ed recdef: admit names/atts;
wenzelm
parents: 8625
diff changeset
   242
    val eq_atts = map (map (prep_att thy)) raw_eq_atts;
b9475dad85ed recdef: admit names/atts;
wenzelm
parents: 8625
diff changeset
   243
9859
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   244
    val (cs, ss, congs, wfs) = prep_hints thy hints;
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   245
    val (thy, {rules = rules_idx, induct, tcs}) = tfl_fn thy cs ss congs wfs name R eqs;
8657
b9475dad85ed recdef: admit names/atts;
wenzelm
parents: 8625
diff changeset
   246
    val rules = map (map #1) (Library.partition_eq Library.eq_snd rules_idx);
b9475dad85ed recdef: admit names/atts;
wenzelm
parents: 8625
diff changeset
   247
    val simp_att = if null tcs then [Simplifier.simp_add_global] else [];
b9475dad85ed recdef: admit names/atts;
wenzelm
parents: 8625
diff changeset
   248
8430
dbd897e0d804 adapted to new PureThy.add_thms etc.;
wenzelm
parents: 7798
diff changeset
   249
    val case_numbers = map Library.string_of_int (1 upto Thm.nprems_of induct);
8657
b9475dad85ed recdef: admit names/atts;
wenzelm
parents: 8625
diff changeset
   250
    val (thy, (simps' :: rules', [induct'])) =
7798
42e94b618f34 return stored thms with proper naming in derivation;
wenzelm
parents: 7262
diff changeset
   251
      thy
6439
7eea9f25dc49 'HOL/recdef' theory data;
wenzelm
parents: 6429
diff changeset
   252
      |> Theory.add_path bname
8657
b9475dad85ed recdef: admit names/atts;
wenzelm
parents: 8625
diff changeset
   253
      |> PureThy.add_thmss ((("simps", flat rules), simp_att) :: ((eq_names ~~ rules) ~~ eq_atts))
8430
dbd897e0d804 adapted to new PureThy.add_thms etc.;
wenzelm
parents: 7798
diff changeset
   254
      |>>> PureThy.add_thms [(("induct", induct), [RuleCases.case_names case_numbers])];
8657
b9475dad85ed recdef: admit names/atts;
wenzelm
parents: 8625
diff changeset
   255
    val result = {simps = simps', rules = rules', induct = induct', tcs = tcs};
7798
42e94b618f34 return stored thms with proper naming in derivation;
wenzelm
parents: 7262
diff changeset
   256
    val thy =
42e94b618f34 return stored thms with proper naming in derivation;
wenzelm
parents: 7262
diff changeset
   257
      thy
6439
7eea9f25dc49 'HOL/recdef' theory data;
wenzelm
parents: 6429
diff changeset
   258
      |> put_recdef name result
6429
9771ce553e56 Wrapper module for Konrad Slind's TFL package.
wenzelm
parents:
diff changeset
   259
      |> Theory.parent_path;
7798
42e94b618f34 return stored thms with proper naming in derivation;
wenzelm
parents: 7262
diff changeset
   260
  in (thy, result) end;
6429
9771ce553e56 Wrapper module for Konrad Slind's TFL package.
wenzelm
parents:
diff changeset
   261
9859
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   262
val add_recdef = gen_add_recdef Tfl.define Attrib.global_attribute prepare_hints;
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   263
fun add_recdef_i x y z = gen_add_recdef Tfl.define_i (K I) prepare_hints_i x y z ();
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   264
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   265
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   266
(* add_recdef_old -- legacy interface *)
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   267
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   268
fun prepare_hints_old thy (ss, thms) =
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   269
  let val {simps, congs, wfs} = get_global_hints thy
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   270
  in (Classical.claset_of thy, ss addsimps simps, map #2 (add_congs thms congs), wfs) end;
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   271
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   272
val add_recdef_old = gen_add_recdef Tfl.define Attrib.global_attribute prepare_hints_old;
6429
9771ce553e56 Wrapper module for Konrad Slind's TFL package.
wenzelm
parents:
diff changeset
   273
9771ce553e56 Wrapper module for Konrad Slind's TFL package.
wenzelm
parents:
diff changeset
   274
6557
d7e7532c128a peoper defer_recdef interface;
wenzelm
parents: 6520
diff changeset
   275
d7e7532c128a peoper defer_recdef interface;
wenzelm
parents: 6520
diff changeset
   276
(** defer_recdef(_i) **)
d7e7532c128a peoper defer_recdef interface;
wenzelm
parents: 6520
diff changeset
   277
d7e7532c128a peoper defer_recdef interface;
wenzelm
parents: 6520
diff changeset
   278
fun gen_defer_recdef tfl_fn app_thms raw_name eqs raw_congs thy =
d7e7532c128a peoper defer_recdef interface;
wenzelm
parents: 6520
diff changeset
   279
  let
d7e7532c128a peoper defer_recdef interface;
wenzelm
parents: 6520
diff changeset
   280
    val name = Sign.intern_const (Theory.sign_of thy) raw_name;
d7e7532c128a peoper defer_recdef interface;
wenzelm
parents: 6520
diff changeset
   281
    val bname = Sign.base_name name;
d7e7532c128a peoper defer_recdef interface;
wenzelm
parents: 6520
diff changeset
   282
d7e7532c128a peoper defer_recdef interface;
wenzelm
parents: 6520
diff changeset
   283
    val _ = requires_recdef thy;
d7e7532c128a peoper defer_recdef interface;
wenzelm
parents: 6520
diff changeset
   284
    val _ = message ("Deferred recursive function " ^ quote name ^ " ...");
d7e7532c128a peoper defer_recdef interface;
wenzelm
parents: 6520
diff changeset
   285
d7e7532c128a peoper defer_recdef interface;
wenzelm
parents: 6520
diff changeset
   286
    val (thy1, congs) = thy |> app_thms raw_congs;
9859
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   287
    val (thy2, induct_rules) = tfl_fn thy1 congs name eqs;
8430
dbd897e0d804 adapted to new PureThy.add_thms etc.;
wenzelm
parents: 7798
diff changeset
   288
    val (thy3, [induct_rules']) =
6557
d7e7532c128a peoper defer_recdef interface;
wenzelm
parents: 6520
diff changeset
   289
      thy2
d7e7532c128a peoper defer_recdef interface;
wenzelm
parents: 6520
diff changeset
   290
      |> Theory.add_path bname
d7e7532c128a peoper defer_recdef interface;
wenzelm
parents: 6520
diff changeset
   291
      |> PureThy.add_thms [(("induct_rules", induct_rules), [])]
8430
dbd897e0d804 adapted to new PureThy.add_thms etc.;
wenzelm
parents: 7798
diff changeset
   292
      |>> Theory.parent_path;
dbd897e0d804 adapted to new PureThy.add_thms etc.;
wenzelm
parents: 7798
diff changeset
   293
  in (thy3, {induct_rules = induct_rules'}) end;
6557
d7e7532c128a peoper defer_recdef interface;
wenzelm
parents: 6520
diff changeset
   294
d7e7532c128a peoper defer_recdef interface;
wenzelm
parents: 6520
diff changeset
   295
val defer_recdef = gen_defer_recdef Tfl.defer IsarThy.apply_theorems;
d7e7532c128a peoper defer_recdef interface;
wenzelm
parents: 6520
diff changeset
   296
val defer_recdef_i = gen_defer_recdef Tfl.defer_i IsarThy.apply_theorems_i;
d7e7532c128a peoper defer_recdef interface;
wenzelm
parents: 6520
diff changeset
   297
d7e7532c128a peoper defer_recdef interface;
wenzelm
parents: 6520
diff changeset
   298
d7e7532c128a peoper defer_recdef interface;
wenzelm
parents: 6520
diff changeset
   299
6439
7eea9f25dc49 'HOL/recdef' theory data;
wenzelm
parents: 6429
diff changeset
   300
(** package setup **)
7eea9f25dc49 'HOL/recdef' theory data;
wenzelm
parents: 6429
diff changeset
   301
7eea9f25dc49 'HOL/recdef' theory data;
wenzelm
parents: 6429
diff changeset
   302
(* setup theory *)
7eea9f25dc49 'HOL/recdef' theory data;
wenzelm
parents: 6429
diff changeset
   303
9859
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   304
val setup =
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   305
 [GlobalRecdefData.init, LocalRecdefData.init,
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   306
  Attrib.add_attributes
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   307
   [("recdef_simp", simp_attr, "declare recdef simp rule"),
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   308
    ("recdef_cong", cong_attr, "declare recdef cong rule"),
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   309
    ("recdef_wf", wf_attr, "declare recdef wf rule")]];
6439
7eea9f25dc49 'HOL/recdef' theory data;
wenzelm
parents: 6429
diff changeset
   310
7eea9f25dc49 'HOL/recdef' theory data;
wenzelm
parents: 6429
diff changeset
   311
6429
9771ce553e56 Wrapper module for Konrad Slind's TFL package.
wenzelm
parents:
diff changeset
   312
(* outer syntax *)
9771ce553e56 Wrapper module for Konrad Slind's TFL package.
wenzelm
parents:
diff changeset
   313
6723
f342449d73ca outer syntax keyword classification;
wenzelm
parents: 6576
diff changeset
   314
local structure P = OuterParse and K = OuterSyntax.Keyword in
6429
9771ce553e56 Wrapper module for Konrad Slind's TFL package.
wenzelm
parents:
diff changeset
   315
9859
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   316
val hints =
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   317
  P.$$$ "(" |-- P.!!! (P.position (P.$$$ "hints" -- P.arguments) --| P.$$$ ")") >> Args.src;
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   318
6429
9771ce553e56 Wrapper module for Konrad Slind's TFL package.
wenzelm
parents:
diff changeset
   319
val recdef_decl =
9859
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   320
  P.name -- P.term -- Scan.repeat1 (P.opt_thm_name ":" -- P.prop --| P.marg_comment)
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   321
    -- Scan.option hints
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   322
  >> (fn (((f, R), eqs), src) => #1 o add_recdef f R (map P.triple_swap eqs) src);
6429
9771ce553e56 Wrapper module for Konrad Slind's TFL package.
wenzelm
parents:
diff changeset
   323
9771ce553e56 Wrapper module for Konrad Slind's TFL package.
wenzelm
parents:
diff changeset
   324
val recdefP =
6723
f342449d73ca outer syntax keyword classification;
wenzelm
parents: 6576
diff changeset
   325
  OuterSyntax.command "recdef" "define general recursive functions (TFL)" K.thy_decl
6429
9771ce553e56 Wrapper module for Konrad Slind's TFL package.
wenzelm
parents:
diff changeset
   326
    (recdef_decl >> Toplevel.theory);
9771ce553e56 Wrapper module for Konrad Slind's TFL package.
wenzelm
parents:
diff changeset
   327
6557
d7e7532c128a peoper defer_recdef interface;
wenzelm
parents: 6520
diff changeset
   328
d7e7532c128a peoper defer_recdef interface;
wenzelm
parents: 6520
diff changeset
   329
val defer_recdef_decl =
8657
b9475dad85ed recdef: admit names/atts;
wenzelm
parents: 8625
diff changeset
   330
  P.name -- Scan.repeat1 P.prop --
6723
f342449d73ca outer syntax keyword classification;
wenzelm
parents: 6576
diff changeset
   331
  Scan.optional (P.$$$ "(" |-- P.$$$ "congs" |-- P.!!! (P.xthms1 --| P.$$$ ")")) []
6557
d7e7532c128a peoper defer_recdef interface;
wenzelm
parents: 6520
diff changeset
   332
  >> (fn ((f, eqs), congs) => #1 o defer_recdef f eqs congs);
d7e7532c128a peoper defer_recdef interface;
wenzelm
parents: 6520
diff changeset
   333
d7e7532c128a peoper defer_recdef interface;
wenzelm
parents: 6520
diff changeset
   334
val defer_recdefP =
6723
f342449d73ca outer syntax keyword classification;
wenzelm
parents: 6576
diff changeset
   335
  OuterSyntax.command "defer_recdef" "defer general recursive functions (TFL)" K.thy_decl
6557
d7e7532c128a peoper defer_recdef interface;
wenzelm
parents: 6520
diff changeset
   336
    (defer_recdef_decl >> Toplevel.theory);
d7e7532c128a peoper defer_recdef interface;
wenzelm
parents: 6520
diff changeset
   337
9859
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   338
val _ = OuterSyntax.add_keywords ["hints"];
6557
d7e7532c128a peoper defer_recdef interface;
wenzelm
parents: 6520
diff changeset
   339
val _ = OuterSyntax.add_parsers [recdefP, defer_recdefP];
6429
9771ce553e56 Wrapper module for Konrad Slind's TFL package.
wenzelm
parents:
diff changeset
   340
9771ce553e56 Wrapper module for Konrad Slind's TFL package.
wenzelm
parents:
diff changeset
   341
end;
9771ce553e56 Wrapper module for Konrad Slind's TFL package.
wenzelm
parents:
diff changeset
   342
9771ce553e56 Wrapper module for Konrad Slind's TFL package.
wenzelm
parents:
diff changeset
   343
9771ce553e56 Wrapper module for Konrad Slind's TFL package.
wenzelm
parents:
diff changeset
   344
end;