author | blanchet |
Fri, 07 Mar 2014 01:02:21 +0100 | |
changeset 55966 | 972f0aa7091b |
parent 55869 | 54ddb003e128 |
child 56121 | 52e8f110fec3 |
permissions | -rw-r--r-- |
55061 | 1 |
(* Title: HOL/Tools/BNF/bnf_lfp_rec_sugar.ML |
54246
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
2 |
Author: Lorenz Panny, TU Muenchen |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
3 |
Author: Jasmin Blanchette, TU Muenchen |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
4 |
Copyright 2013 |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
5 |
|
55538 | 6 |
Recursor sugar ("primrec"). |
54246
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
7 |
*) |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
8 |
|
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
9 |
signature BNF_LFP_REC_SUGAR = |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
10 |
sig |
55571 | 11 |
type basic_lfp_sugar = |
12 |
{T: typ, |
|
13 |
fp_res_index: int, |
|
55574
4a940ebceef8
rewrote a small portion of code to avoid dependency on low-level constant
blanchet
parents:
55573
diff
changeset
|
14 |
C: typ, |
4a940ebceef8
rewrote a small portion of code to avoid dependency on low-level constant
blanchet
parents:
55573
diff
changeset
|
15 |
fun_arg_Tsss : typ list list list, |
55571 | 16 |
ctr_defs: thm list, |
17 |
ctr_sugar: Ctr_Sugar.ctr_sugar, |
|
18 |
recx: term, |
|
19 |
rec_thms: thm list}; |
|
20 |
||
21 |
type lfp_rec_extension = |
|
55575
a5e33e18fb5c
moved 'primrec' up (for real this time) and removed temporary 'old_primrec'
blanchet
parents:
55574
diff
changeset
|
22 |
{nested_simps: thm list, |
a5e33e18fb5c
moved 'primrec' up (for real this time) and removed temporary 'old_primrec'
blanchet
parents:
55574
diff
changeset
|
23 |
is_new_datatype: Proof.context -> string -> bool, |
55772
367ec44763fd
correct most general type for mutual recursion when several identical types are involved
blanchet
parents:
55576
diff
changeset
|
24 |
get_basic_lfp_sugars: binding list -> typ list -> term list -> |
367ec44763fd
correct most general type for mutual recursion when several identical types are involved
blanchet
parents:
55576
diff
changeset
|
25 |
(term * term list list) list list -> local_theory -> |
367ec44763fd
correct most general type for mutual recursion when several identical types are involved
blanchet
parents:
55576
diff
changeset
|
26 |
typ list * int list * basic_lfp_sugar list * thm list * thm list * thm * bool * local_theory, |
55576 | 27 |
rewrite_nested_rec_call: Proof.context -> (term -> bool) -> (string -> int) -> typ list -> |
28 |
term -> term -> term -> term}; |
|
55575
a5e33e18fb5c
moved 'primrec' up (for real this time) and removed temporary 'old_primrec'
blanchet
parents:
55574
diff
changeset
|
29 |
|
a5e33e18fb5c
moved 'primrec' up (for real this time) and removed temporary 'old_primrec'
blanchet
parents:
55574
diff
changeset
|
30 |
exception PRIMREC of string * term list; |
55571 | 31 |
|
32 |
val register_lfp_rec_extension: lfp_rec_extension -> theory -> theory |
|
33 |
||
54246
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
34 |
val add_primrec: (binding * typ option * mixfix) list -> |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
35 |
(Attrib.binding * term) list -> local_theory -> (term list * thm list list) * local_theory |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
36 |
val add_primrec_cmd: (binding * string option * mixfix) list -> |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
37 |
(Attrib.binding * string) list -> local_theory -> (term list * thm list list) * local_theory |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
38 |
val add_primrec_global: (binding * typ option * mixfix) list -> |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
39 |
(Attrib.binding * term) list -> theory -> (term list * thm list list) * theory |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
40 |
val add_primrec_overloaded: (string * (string * typ) * bool) list -> |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
41 |
(binding * typ option * mixfix) list -> |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
42 |
(Attrib.binding * term) list -> theory -> (term list * thm list list) * theory |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
43 |
val add_primrec_simple: ((binding * typ) * mixfix) list -> term list -> |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
44 |
local_theory -> (string list * (term list * (int list list * thm list list))) * local_theory |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
45 |
end; |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
46 |
|
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
47 |
structure BNF_LFP_Rec_Sugar : BNF_LFP_REC_SUGAR = |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
48 |
struct |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
49 |
|
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
50 |
open Ctr_Sugar |
55575
a5e33e18fb5c
moved 'primrec' up (for real this time) and removed temporary 'old_primrec'
blanchet
parents:
55574
diff
changeset
|
51 |
open Ctr_Sugar_Util |
55574
4a940ebceef8
rewrote a small portion of code to avoid dependency on low-level constant
blanchet
parents:
55573
diff
changeset
|
52 |
open Ctr_Sugar_General_Tactics |
54246
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
53 |
open BNF_FP_Rec_Sugar_Util |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
54 |
|
55575
a5e33e18fb5c
moved 'primrec' up (for real this time) and removed temporary 'old_primrec'
blanchet
parents:
55574
diff
changeset
|
55 |
val inductN = "induct" |
a5e33e18fb5c
moved 'primrec' up (for real this time) and removed temporary 'old_primrec'
blanchet
parents:
55574
diff
changeset
|
56 |
val simpsN = "simps" |
a5e33e18fb5c
moved 'primrec' up (for real this time) and removed temporary 'old_primrec'
blanchet
parents:
55574
diff
changeset
|
57 |
|
54246
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
58 |
val nitpicksimp_attrs = @{attributes [nitpick_simp]}; |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
59 |
val simp_attrs = @{attributes [simp]}; |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
60 |
val code_nitpicksimp_simp_attrs = Code.add_default_eqn_attrib :: nitpicksimp_attrs @ simp_attrs; |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
61 |
|
55528
c367f4f3e5d4
have 'primrec_new' fall back on old 'primrec' when given old-style datatypes
blanchet
parents:
55527
diff
changeset
|
62 |
exception OLD_PRIMREC of unit; |
55527 | 63 |
exception PRIMREC of string * term list; |
54246
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
64 |
|
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
65 |
datatype rec_call = |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
66 |
No_Rec of int * typ | |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
67 |
Mutual_Rec of (int * typ) * (int * typ) | |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
68 |
Nested_Rec of int * typ; |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
69 |
|
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
70 |
type rec_ctr_spec = |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
71 |
{ctr: term, |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
72 |
offset: int, |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
73 |
calls: rec_call list, |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
74 |
rec_thm: thm}; |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
75 |
|
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
76 |
type rec_spec = |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
77 |
{recx: term, |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
78 |
nested_map_idents: thm list, |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
79 |
nested_map_comps: thm list, |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
80 |
ctr_specs: rec_ctr_spec list}; |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
81 |
|
55538 | 82 |
type basic_lfp_sugar = |
83 |
{T: typ, |
|
55539
0819931d652d
simplified data structure by reducing the incidence of clumsy indices
blanchet
parents:
55538
diff
changeset
|
84 |
fp_res_index: int, |
55574
4a940ebceef8
rewrote a small portion of code to avoid dependency on low-level constant
blanchet
parents:
55573
diff
changeset
|
85 |
C: typ, |
4a940ebceef8
rewrote a small portion of code to avoid dependency on low-level constant
blanchet
parents:
55573
diff
changeset
|
86 |
fun_arg_Tsss : typ list list list, |
55539
0819931d652d
simplified data structure by reducing the incidence of clumsy indices
blanchet
parents:
55538
diff
changeset
|
87 |
ctr_defs: thm list, |
0819931d652d
simplified data structure by reducing the incidence of clumsy indices
blanchet
parents:
55538
diff
changeset
|
88 |
ctr_sugar: ctr_sugar, |
55570 | 89 |
recx: term, |
90 |
rec_thms: thm list}; |
|
55538 | 91 |
|
55571 | 92 |
type lfp_rec_extension = |
55575
a5e33e18fb5c
moved 'primrec' up (for real this time) and removed temporary 'old_primrec'
blanchet
parents:
55574
diff
changeset
|
93 |
{nested_simps: thm list, |
a5e33e18fb5c
moved 'primrec' up (for real this time) and removed temporary 'old_primrec'
blanchet
parents:
55574
diff
changeset
|
94 |
is_new_datatype: Proof.context -> string -> bool, |
55772
367ec44763fd
correct most general type for mutual recursion when several identical types are involved
blanchet
parents:
55576
diff
changeset
|
95 |
get_basic_lfp_sugars: binding list -> typ list -> term list -> |
367ec44763fd
correct most general type for mutual recursion when several identical types are involved
blanchet
parents:
55576
diff
changeset
|
96 |
(term * term list list) list list -> local_theory -> |
367ec44763fd
correct most general type for mutual recursion when several identical types are involved
blanchet
parents:
55576
diff
changeset
|
97 |
typ list * int list * basic_lfp_sugar list * thm list * thm list * thm * bool * local_theory, |
55576 | 98 |
rewrite_nested_rec_call: Proof.context -> (term -> bool) -> (string -> int) -> typ list -> |
99 |
term -> term -> term -> term}; |
|
55571 | 100 |
|
101 |
structure Data = Theory_Data |
|
102 |
( |
|
103 |
type T = lfp_rec_extension option; |
|
104 |
val empty = NONE; |
|
105 |
val extend = I; |
|
106 |
val merge = merge_options; |
|
107 |
); |
|
55538 | 108 |
|
55571 | 109 |
val register_lfp_rec_extension = Data.put o SOME; |
110 |
||
55575
a5e33e18fb5c
moved 'primrec' up (for real this time) and removed temporary 'old_primrec'
blanchet
parents:
55574
diff
changeset
|
111 |
fun nested_simps ctxt = |
a5e33e18fb5c
moved 'primrec' up (for real this time) and removed temporary 'old_primrec'
blanchet
parents:
55574
diff
changeset
|
112 |
(case Data.get (Proof_Context.theory_of ctxt) of |
a5e33e18fb5c
moved 'primrec' up (for real this time) and removed temporary 'old_primrec'
blanchet
parents:
55574
diff
changeset
|
113 |
SOME {nested_simps, ...} => nested_simps |
a5e33e18fb5c
moved 'primrec' up (for real this time) and removed temporary 'old_primrec'
blanchet
parents:
55574
diff
changeset
|
114 |
| NONE => []); |
a5e33e18fb5c
moved 'primrec' up (for real this time) and removed temporary 'old_primrec'
blanchet
parents:
55574
diff
changeset
|
115 |
|
55571 | 116 |
fun is_new_datatype ctxt = |
117 |
(case Data.get (Proof_Context.theory_of ctxt) of |
|
118 |
SOME {is_new_datatype, ...} => is_new_datatype ctxt |
|
119 |
| NONE => K false); |
|
120 |
||
55772
367ec44763fd
correct most general type for mutual recursion when several identical types are involved
blanchet
parents:
55576
diff
changeset
|
121 |
fun get_basic_lfp_sugars bs arg_Ts callers callssss lthy = |
55571 | 122 |
(case Data.get (Proof_Context.theory_of lthy) of |
55772
367ec44763fd
correct most general type for mutual recursion when several identical types are involved
blanchet
parents:
55576
diff
changeset
|
123 |
SOME {get_basic_lfp_sugars, ...} => get_basic_lfp_sugars bs arg_Ts callers callssss lthy |
367ec44763fd
correct most general type for mutual recursion when several identical types are involved
blanchet
parents:
55576
diff
changeset
|
124 |
| NONE => error "Functionality not loaded yet"); |
55571 | 125 |
|
55575
a5e33e18fb5c
moved 'primrec' up (for real this time) and removed temporary 'old_primrec'
blanchet
parents:
55574
diff
changeset
|
126 |
fun rewrite_nested_rec_call ctxt = |
55571 | 127 |
(case Data.get (Proof_Context.theory_of ctxt) of |
55575
a5e33e18fb5c
moved 'primrec' up (for real this time) and removed temporary 'old_primrec'
blanchet
parents:
55574
diff
changeset
|
128 |
SOME {rewrite_nested_rec_call, ...} => rewrite_nested_rec_call ctxt); |
54246
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
129 |
|
55772
367ec44763fd
correct most general type for mutual recursion when several identical types are involved
blanchet
parents:
55576
diff
changeset
|
130 |
fun rec_specs_of bs arg_Ts res_Ts callers callssss0 lthy0 = |
55538 | 131 |
let |
132 |
val thy = Proof_Context.theory_of lthy0; |
|
54246
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
133 |
|
55538 | 134 |
val (missing_arg_Ts, perm0_kks, basic_lfp_sugars, nested_map_idents, nested_map_comps, |
55571 | 135 |
induct_thm, n2m, lthy) = |
55772
367ec44763fd
correct most general type for mutual recursion when several identical types are involved
blanchet
parents:
55576
diff
changeset
|
136 |
get_basic_lfp_sugars bs arg_Ts callers callssss0 lthy0; |
54246
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
137 |
|
55539
0819931d652d
simplified data structure by reducing the incidence of clumsy indices
blanchet
parents:
55538
diff
changeset
|
138 |
val perm_basic_lfp_sugars = sort (int_ord o pairself #fp_res_index) basic_lfp_sugars; |
55538 | 139 |
|
55539
0819931d652d
simplified data structure by reducing the incidence of clumsy indices
blanchet
parents:
55538
diff
changeset
|
140 |
val indices = map #fp_res_index basic_lfp_sugars; |
0819931d652d
simplified data structure by reducing the incidence of clumsy indices
blanchet
parents:
55538
diff
changeset
|
141 |
val perm_indices = map #fp_res_index perm_basic_lfp_sugars; |
55538 | 142 |
|
55539
0819931d652d
simplified data structure by reducing the incidence of clumsy indices
blanchet
parents:
55538
diff
changeset
|
143 |
val perm_ctrss = map (#ctrs o #ctr_sugar) perm_basic_lfp_sugars; |
54246
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
144 |
|
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
145 |
val nn0 = length arg_Ts; |
55539
0819931d652d
simplified data structure by reducing the incidence of clumsy indices
blanchet
parents:
55538
diff
changeset
|
146 |
val nn = length perm_ctrss; |
54246
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
147 |
val kks = 0 upto nn - 1; |
55539
0819931d652d
simplified data structure by reducing the incidence of clumsy indices
blanchet
parents:
55538
diff
changeset
|
148 |
|
0819931d652d
simplified data structure by reducing the incidence of clumsy indices
blanchet
parents:
55538
diff
changeset
|
149 |
val perm_ctr_offsets = map (fn kk => Integer.sum (map length (take kk perm_ctrss))) kks; |
54246
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
150 |
|
55539
0819931d652d
simplified data structure by reducing the incidence of clumsy indices
blanchet
parents:
55538
diff
changeset
|
151 |
val perm_lfpTs = map (body_type o fastype_of o hd) perm_ctrss; |
55574
4a940ebceef8
rewrote a small portion of code to avoid dependency on low-level constant
blanchet
parents:
55573
diff
changeset
|
152 |
val perm_Cs = map #C perm_basic_lfp_sugars; |
4a940ebceef8
rewrote a small portion of code to avoid dependency on low-level constant
blanchet
parents:
55573
diff
changeset
|
153 |
val perm_fun_arg_Tssss = map #fun_arg_Tsss perm_basic_lfp_sugars; |
54246
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
154 |
|
55480
59cc4a8bc28a
allow different functions to recurse on the same type, like in the old package
blanchet
parents:
55464
diff
changeset
|
155 |
fun unpermute0 perm0_xs = permute_like_unique (op =) perm0_kks kks perm0_xs; |
59cc4a8bc28a
allow different functions to recurse on the same type, like in the old package
blanchet
parents:
55464
diff
changeset
|
156 |
fun unpermute perm_xs = permute_like_unique (op =) perm_indices indices perm_xs; |
54246
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
157 |
|
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
158 |
val induct_thms = unpermute0 (conj_dests nn induct_thm); |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
159 |
|
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
160 |
val lfpTs = unpermute perm_lfpTs; |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
161 |
val Cs = unpermute perm_Cs; |
55539
0819931d652d
simplified data structure by reducing the incidence of clumsy indices
blanchet
parents:
55538
diff
changeset
|
162 |
val ctr_offsets = unpermute perm_ctr_offsets; |
54246
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
163 |
|
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
164 |
val As_rho = tvar_subst thy (take nn0 lfpTs) arg_Ts; |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
165 |
val Cs_rho = map (fst o dest_TVar) Cs ~~ pad_list HOLogic.unitT nn res_Ts; |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
166 |
|
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
167 |
val substA = Term.subst_TVars As_rho; |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
168 |
val substAT = Term.typ_subst_TVars As_rho; |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
169 |
val substCT = Term.typ_subst_TVars Cs_rho; |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
170 |
val substACT = substAT o substCT; |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
171 |
|
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
172 |
val perm_Cs' = map substCT perm_Cs; |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
173 |
|
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
174 |
fun call_of [i] [T] = (if exists_subtype_in Cs T then Nested_Rec else No_Rec) (i, substACT T) |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
175 |
| call_of [i, i'] [T, T'] = Mutual_Rec ((i, substACT T), (i', substACT T')); |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
176 |
|
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
177 |
fun mk_ctr_spec ctr offset fun_arg_Tss rec_thm = |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
178 |
let |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
179 |
val (fun_arg_hss, _) = indexedd fun_arg_Tss 0; |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
180 |
val fun_arg_hs = flat_rec_arg_args fun_arg_hss; |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
181 |
val fun_arg_iss = map (map (find_index_eq fun_arg_hs)) fun_arg_hss; |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
182 |
in |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
183 |
{ctr = substA ctr, offset = offset, calls = map2 call_of fun_arg_iss fun_arg_Tss, |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
184 |
rec_thm = rec_thm} |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
185 |
end; |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
186 |
|
55539
0819931d652d
simplified data structure by reducing the incidence of clumsy indices
blanchet
parents:
55538
diff
changeset
|
187 |
fun mk_ctr_specs fp_res_index k ctrs rec_thms = |
0819931d652d
simplified data structure by reducing the incidence of clumsy indices
blanchet
parents:
55538
diff
changeset
|
188 |
map4 mk_ctr_spec ctrs (k upto k + length ctrs - 1) (nth perm_fun_arg_Tssss fp_res_index) |
0819931d652d
simplified data structure by reducing the incidence of clumsy indices
blanchet
parents:
55538
diff
changeset
|
189 |
rec_thms; |
54246
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
190 |
|
55539
0819931d652d
simplified data structure by reducing the incidence of clumsy indices
blanchet
parents:
55538
diff
changeset
|
191 |
fun mk_spec ctr_offset |
55570 | 192 |
({T, fp_res_index, ctr_sugar = {ctrs, ...}, recx, rec_thms, ...} : basic_lfp_sugar) = |
55869 | 193 |
{recx = mk_co_rec thy Least_FP (substAT T) perm_Cs' recx, |
55538 | 194 |
nested_map_idents = nested_map_idents, nested_map_comps = nested_map_comps, |
55570 | 195 |
ctr_specs = mk_ctr_specs fp_res_index ctr_offset ctrs rec_thms}; |
54246
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
196 |
in |
55571 | 197 |
((n2m, map2 mk_spec ctr_offsets basic_lfp_sugars, missing_arg_Ts, induct_thm, induct_thms), |
198 |
lthy) |
|
54246
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
199 |
end; |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
200 |
|
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
201 |
val undef_const = Const (@{const_name undefined}, dummyT); |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
202 |
|
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
203 |
type eqn_data = { |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
204 |
fun_name: string, |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
205 |
rec_type: typ, |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
206 |
ctr: term, |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
207 |
ctr_args: term list, |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
208 |
left_args: term list, |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
209 |
right_args: term list, |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
210 |
res_type: typ, |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
211 |
rhs_term: term, |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
212 |
user_eqn: term |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
213 |
}; |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
214 |
|
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
215 |
fun dissect_eqn lthy fun_names eqn' = |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
216 |
let |
54979
d7593bfccf25
correctly extract code RHS, with loose bound variables
blanchet
parents:
54952
diff
changeset
|
217 |
val eqn = drop_all eqn' |> HOLogic.dest_Trueprop |
54246
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
218 |
handle TERM _ => |
55575
a5e33e18fb5c
moved 'primrec' up (for real this time) and removed temporary 'old_primrec'
blanchet
parents:
55574
diff
changeset
|
219 |
raise PRIMREC ("malformed function equation (expected \"lhs = rhs\")", [eqn']); |
54246
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
220 |
val (lhs, rhs) = HOLogic.dest_eq eqn |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
221 |
handle TERM _ => |
55575
a5e33e18fb5c
moved 'primrec' up (for real this time) and removed temporary 'old_primrec'
blanchet
parents:
55574
diff
changeset
|
222 |
raise PRIMREC ("malformed function equation (expected \"lhs = rhs\")", [eqn']); |
54246
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
223 |
val (fun_name, args) = strip_comb lhs |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
224 |
|>> (fn x => if is_Free x then fst (dest_Free x) |
55575
a5e33e18fb5c
moved 'primrec' up (for real this time) and removed temporary 'old_primrec'
blanchet
parents:
55574
diff
changeset
|
225 |
else raise PRIMREC ("malformed function equation (does not start with free)", [eqn])); |
54246
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
226 |
val (left_args, rest) = take_prefix is_Free args; |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
227 |
val (nonfrees, right_args) = take_suffix is_Free rest; |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
228 |
val num_nonfrees = length nonfrees; |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
229 |
val _ = num_nonfrees = 1 orelse if num_nonfrees = 0 then |
55575
a5e33e18fb5c
moved 'primrec' up (for real this time) and removed temporary 'old_primrec'
blanchet
parents:
55574
diff
changeset
|
230 |
raise PRIMREC ("constructor pattern missing in left-hand side", [eqn]) else |
a5e33e18fb5c
moved 'primrec' up (for real this time) and removed temporary 'old_primrec'
blanchet
parents:
55574
diff
changeset
|
231 |
raise PRIMREC ("more than one non-variable argument in left-hand side", [eqn]); |
54246
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
232 |
val _ = member (op =) fun_names fun_name orelse |
55575
a5e33e18fb5c
moved 'primrec' up (for real this time) and removed temporary 'old_primrec'
blanchet
parents:
55574
diff
changeset
|
233 |
raise PRIMREC ("malformed function equation (does not start with function name)", [eqn]); |
54246
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
234 |
|
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
235 |
val (ctr, ctr_args) = strip_comb (the_single nonfrees); |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
236 |
val _ = try (num_binder_types o fastype_of) ctr = SOME (length ctr_args) orelse |
55575
a5e33e18fb5c
moved 'primrec' up (for real this time) and removed temporary 'old_primrec'
blanchet
parents:
55574
diff
changeset
|
237 |
raise PRIMREC ("partially applied constructor in pattern", [eqn]); |
54246
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
238 |
val _ = let val d = duplicates (op =) (left_args @ ctr_args @ right_args) in null d orelse |
55575
a5e33e18fb5c
moved 'primrec' up (for real this time) and removed temporary 'old_primrec'
blanchet
parents:
55574
diff
changeset
|
239 |
raise PRIMREC ("duplicate variable \"" ^ Syntax.string_of_term lthy (hd d) ^ |
a5e33e18fb5c
moved 'primrec' up (for real this time) and removed temporary 'old_primrec'
blanchet
parents:
55574
diff
changeset
|
240 |
"\" in left-hand side", [eqn]) end; |
54246
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
241 |
val _ = forall is_Free ctr_args orelse |
55575
a5e33e18fb5c
moved 'primrec' up (for real this time) and removed temporary 'old_primrec'
blanchet
parents:
55574
diff
changeset
|
242 |
raise PRIMREC ("non-primitive pattern in left-hand side", [eqn]); |
54246
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
243 |
val _ = |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
244 |
let val b = fold_aterms (fn x as Free (v, _) => |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
245 |
if (not (member (op =) (left_args @ ctr_args @ right_args) x) andalso |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
246 |
not (member (op =) fun_names v) andalso |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
247 |
not (Variable.is_fixed lthy v)) then cons x else I | _ => I) rhs [] |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
248 |
in |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
249 |
null b orelse |
55575
a5e33e18fb5c
moved 'primrec' up (for real this time) and removed temporary 'old_primrec'
blanchet
parents:
55574
diff
changeset
|
250 |
raise PRIMREC ("extra variable(s) in right-hand side: " ^ |
a5e33e18fb5c
moved 'primrec' up (for real this time) and removed temporary 'old_primrec'
blanchet
parents:
55574
diff
changeset
|
251 |
commas (map (Syntax.string_of_term lthy) b), [eqn]) |
54246
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
252 |
end; |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
253 |
in |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
254 |
{fun_name = fun_name, |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
255 |
rec_type = body_type (type_of ctr), |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
256 |
ctr = ctr, |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
257 |
ctr_args = ctr_args, |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
258 |
left_args = left_args, |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
259 |
right_args = right_args, |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
260 |
res_type = map fastype_of (left_args @ right_args) ---> fastype_of rhs, |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
261 |
rhs_term = rhs, |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
262 |
user_eqn = eqn'} |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
263 |
end; |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
264 |
|
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
265 |
fun subst_rec_calls lthy get_ctr_pos has_call ctr_args mutual_calls nested_calls = |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
266 |
let |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
267 |
fun try_nested_rec bound_Ts y t = |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
268 |
AList.lookup (op =) nested_calls y |
55575
a5e33e18fb5c
moved 'primrec' up (for real this time) and removed temporary 'old_primrec'
blanchet
parents:
55574
diff
changeset
|
269 |
|> Option.map (fn y' => rewrite_nested_rec_call lthy has_call get_ctr_pos bound_Ts y y' t); |
54246
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
270 |
|
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
271 |
fun subst bound_Ts (t as g' $ y) = |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
272 |
let |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
273 |
fun subst_rec () = subst bound_Ts g' $ subst bound_Ts y; |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
274 |
val y_head = head_of y; |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
275 |
in |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
276 |
if not (member (op =) ctr_args y_head) then |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
277 |
subst_rec () |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
278 |
else |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
279 |
(case try_nested_rec bound_Ts y_head t of |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
280 |
SOME t' => t' |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
281 |
| NONE => |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
282 |
let val (g, g_args) = strip_comb g' in |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
283 |
(case try (get_ctr_pos o fst o dest_Free) g of |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
284 |
SOME ctr_pos => |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
285 |
(length g_args >= ctr_pos orelse |
55575
a5e33e18fb5c
moved 'primrec' up (for real this time) and removed temporary 'old_primrec'
blanchet
parents:
55574
diff
changeset
|
286 |
raise PRIMREC ("too few arguments in recursive call", [t]); |
54246
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
287 |
(case AList.lookup (op =) mutual_calls y of |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
288 |
SOME y' => list_comb (y', g_args) |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
289 |
| NONE => subst_rec ())) |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
290 |
| NONE => subst_rec ()) |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
291 |
end) |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
292 |
end |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
293 |
| subst bound_Ts (Abs (v, T, b)) = Abs (v, T, subst (T :: bound_Ts) b) |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
294 |
| subst _ t = t |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
295 |
|
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
296 |
fun subst' t = |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
297 |
if has_call t then |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
298 |
(* FIXME detect this case earlier? *) |
55575
a5e33e18fb5c
moved 'primrec' up (for real this time) and removed temporary 'old_primrec'
blanchet
parents:
55574
diff
changeset
|
299 |
raise PRIMREC ("recursive call not directly applied to constructor argument", [t]) |
54246
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
300 |
else |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
301 |
try_nested_rec [] (head_of t) t |> the_default t |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
302 |
in |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
303 |
subst' o subst [] |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
304 |
end; |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
305 |
|
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
306 |
fun build_rec_arg lthy (funs_data : eqn_data list list) has_call (ctr_spec : rec_ctr_spec) |
54926
28b621fce2f9
more SML-ish (less Haskell-ish) naming convention
blanchet
parents:
54851
diff
changeset
|
307 |
(eqn_data_opt : eqn_data option) = |
28b621fce2f9
more SML-ish (less Haskell-ish) naming convention
blanchet
parents:
54851
diff
changeset
|
308 |
(case eqn_data_opt of |
54246
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
309 |
NONE => undef_const |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
310 |
| SOME {ctr_args, left_args, right_args, rhs_term = t, ...} => |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
311 |
let |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
312 |
val calls = #calls ctr_spec; |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
313 |
val n_args = fold (Integer.add o (fn Mutual_Rec _ => 2 | _ => 1)) calls 0; |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
314 |
|
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
315 |
val no_calls' = tag_list 0 calls |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
316 |
|> map_filter (try (apsnd (fn No_Rec p => p | Mutual_Rec (p, _) => p))); |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
317 |
val mutual_calls' = tag_list 0 calls |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
318 |
|> map_filter (try (apsnd (fn Mutual_Rec (_, p) => p))); |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
319 |
val nested_calls' = tag_list 0 calls |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
320 |
|> map_filter (try (apsnd (fn Nested_Rec p => p))); |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
321 |
|
54851
48a24d371ebb
prevent ambiguity when mutual recursion maps a datatype to itself, which yielded wrong definitions in some cases (e.g. nat)
panny
parents:
54272
diff
changeset
|
322 |
fun ensure_unique frees t = |
48a24d371ebb
prevent ambiguity when mutual recursion maps a datatype to itself, which yielded wrong definitions in some cases (e.g. nat)
panny
parents:
54272
diff
changeset
|
323 |
if member (op =) frees t then Free (the_single (Term.variant_frees t [dest_Free t])) else t; |
48a24d371ebb
prevent ambiguity when mutual recursion maps a datatype to itself, which yielded wrong definitions in some cases (e.g. nat)
panny
parents:
54272
diff
changeset
|
324 |
|
54246
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
325 |
val args = replicate n_args ("", dummyT) |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
326 |
|> Term.rename_wrt_term t |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
327 |
|> map Free |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
328 |
|> fold (fn (ctr_arg_idx, (arg_idx, _)) => |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
329 |
nth_map arg_idx (K (nth ctr_args ctr_arg_idx))) |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
330 |
no_calls' |
54851
48a24d371ebb
prevent ambiguity when mutual recursion maps a datatype to itself, which yielded wrong definitions in some cases (e.g. nat)
panny
parents:
54272
diff
changeset
|
331 |
|> fold (fn (ctr_arg_idx, (arg_idx, T)) => fn xs => |
48a24d371ebb
prevent ambiguity when mutual recursion maps a datatype to itself, which yielded wrong definitions in some cases (e.g. nat)
panny
parents:
54272
diff
changeset
|
332 |
nth_map arg_idx (K (ensure_unique xs (retype_free T (nth ctr_args ctr_arg_idx)))) xs) |
54246
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
333 |
mutual_calls' |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
334 |
|> fold (fn (ctr_arg_idx, (arg_idx, T)) => |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
335 |
nth_map arg_idx (K (retype_free T (nth ctr_args ctr_arg_idx)))) |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
336 |
nested_calls'; |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
337 |
|
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
338 |
val fun_name_ctr_pos_list = |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
339 |
map (fn (x :: _) => (#fun_name x, length (#left_args x))) funs_data; |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
340 |
val get_ctr_pos = try (the o AList.lookup (op =) fun_name_ctr_pos_list) #> the_default ~1; |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
341 |
val mutual_calls = map (apfst (nth ctr_args) o apsnd (nth args o fst)) mutual_calls'; |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
342 |
val nested_calls = map (apfst (nth ctr_args) o apsnd (nth args o fst)) nested_calls'; |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
343 |
in |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
344 |
t |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
345 |
|> subst_rec_calls lthy get_ctr_pos has_call ctr_args mutual_calls nested_calls |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
346 |
|> fold_rev lambda (args @ left_args @ right_args) |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
347 |
end); |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
348 |
|
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
349 |
fun build_defs lthy bs mxs (funs_data : eqn_data list list) (rec_specs : rec_spec list) has_call = |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
350 |
let |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
351 |
val n_funs = length funs_data; |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
352 |
|
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
353 |
val ctr_spec_eqn_data_list' = |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
354 |
(take n_funs rec_specs |> map #ctr_specs) ~~ funs_data |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
355 |
|> maps (uncurry (finds (fn (x, y) => #ctr x = #ctr y)) |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
356 |
##> (fn x => null x orelse |
55575
a5e33e18fb5c
moved 'primrec' up (for real this time) and removed temporary 'old_primrec'
blanchet
parents:
55574
diff
changeset
|
357 |
raise PRIMREC ("excess equations in definition", map #rhs_term x)) #> fst); |
54246
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
358 |
val _ = ctr_spec_eqn_data_list' |> map (fn (_, x) => length x <= 1 orelse |
55575
a5e33e18fb5c
moved 'primrec' up (for real this time) and removed temporary 'old_primrec'
blanchet
parents:
55574
diff
changeset
|
359 |
raise PRIMREC ("multiple equations for constructor", map #user_eqn x)); |
54246
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
360 |
|
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
361 |
val ctr_spec_eqn_data_list = |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
362 |
ctr_spec_eqn_data_list' @ (drop n_funs rec_specs |> maps #ctr_specs |> map (rpair [])); |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
363 |
|
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
364 |
val recs = take n_funs rec_specs |> map #recx; |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
365 |
val rec_args = ctr_spec_eqn_data_list |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
366 |
|> sort ((op <) o pairself (#offset o fst) |> make_ord) |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
367 |
|> map (uncurry (build_rec_arg lthy funs_data has_call) o apsnd (try the_single)); |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
368 |
val ctr_poss = map (fn x => |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
369 |
if length (distinct ((op =) o pairself (length o #left_args)) x) <> 1 then |
55575
a5e33e18fb5c
moved 'primrec' up (for real this time) and removed temporary 'old_primrec'
blanchet
parents:
55574
diff
changeset
|
370 |
raise PRIMREC ("inconstant constructor pattern position for function " ^ |
a5e33e18fb5c
moved 'primrec' up (for real this time) and removed temporary 'old_primrec'
blanchet
parents:
55574
diff
changeset
|
371 |
quote (#fun_name (hd x)), []) |
54246
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
372 |
else |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
373 |
hd x |> #left_args |> length) funs_data; |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
374 |
in |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
375 |
(recs, ctr_poss) |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
376 |
|-> map2 (fn recx => fn ctr_pos => list_comb (recx, rec_args) |> permute_args ctr_pos) |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
377 |
|> Syntax.check_terms lthy |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
378 |
|> map3 (fn b => fn mx => fn t => ((b, mx), ((Binding.conceal (Thm.def_binding b), []), t))) |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
379 |
bs mxs |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
380 |
end; |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
381 |
|
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
382 |
fun find_rec_calls has_call ({ctr, ctr_args, rhs_term, ...} : eqn_data) = |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
383 |
let |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
384 |
fun find bound_Ts (Abs (_, T, b)) ctr_arg = find (T :: bound_Ts) b ctr_arg |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
385 |
| find bound_Ts (t as _ $ _) ctr_arg = |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
386 |
let |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
387 |
val typof = curry fastype_of1 bound_Ts; |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
388 |
val (f', args') = strip_comb t; |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
389 |
val n = find_index (equal ctr_arg o head_of) args'; |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
390 |
in |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
391 |
if n < 0 then |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
392 |
find bound_Ts f' ctr_arg @ maps (fn x => find bound_Ts x ctr_arg) args' |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
393 |
else |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
394 |
let |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
395 |
val (f, args as arg :: _) = chop n args' |>> curry list_comb f' |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
396 |
val (arg_head, arg_args) = Term.strip_comb arg; |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
397 |
in |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
398 |
if has_call f then |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
399 |
mk_partial_compN (length arg_args) (typof arg_head) f :: |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
400 |
maps (fn x => find bound_Ts x ctr_arg) args |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
401 |
else |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
402 |
find bound_Ts f ctr_arg @ maps (fn x => find bound_Ts x ctr_arg) args |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
403 |
end |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
404 |
end |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
405 |
| find _ _ _ = []; |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
406 |
in |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
407 |
map (find [] rhs_term) ctr_args |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
408 |
|> (fn [] => NONE | callss => SOME (ctr, callss)) |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
409 |
end; |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
410 |
|
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
411 |
fun mk_primrec_tac ctxt num_extra_args map_idents map_comps fun_defs recx = |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
412 |
unfold_thms_tac ctxt fun_defs THEN |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
413 |
HEADGOAL (rtac (funpow num_extra_args (fn thm => thm RS fun_cong) recx RS trans)) THEN |
55575
a5e33e18fb5c
moved 'primrec' up (for real this time) and removed temporary 'old_primrec'
blanchet
parents:
55574
diff
changeset
|
414 |
unfold_thms_tac ctxt (nested_simps ctxt @ map_comps @ map_idents) THEN |
54246
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
415 |
HEADGOAL (rtac refl); |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
416 |
|
55535
10194808430d
name derivations in 'primrec' for code extraction from proof terms
blanchet
parents:
55530
diff
changeset
|
417 |
fun prepare_primrec fixes specs lthy0 = |
54246
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
418 |
let |
55535
10194808430d
name derivations in 'primrec' for code extraction from proof terms
blanchet
parents:
55530
diff
changeset
|
419 |
val thy = Proof_Context.theory_of lthy0; |
54272
9d623cada37f
avoid subtle failure in the presence of top sort
blanchet
parents:
54256
diff
changeset
|
420 |
|
54246
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
421 |
val (bs, mxs) = map_split (apfst fst) fixes; |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
422 |
val fun_names = map Binding.name_of bs; |
55535
10194808430d
name derivations in 'primrec' for code extraction from proof terms
blanchet
parents:
55530
diff
changeset
|
423 |
val eqns_data = map (dissect_eqn lthy0 fun_names) specs; |
54246
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
424 |
val funs_data = eqns_data |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
425 |
|> partition_eq ((op =) o pairself #fun_name) |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
426 |
|> finds (fn (x, y) => x = #fun_name (hd y)) fun_names |> fst |
55527 | 427 |
|> map (fn (x, y) => the_single y |
55575
a5e33e18fb5c
moved 'primrec' up (for real this time) and removed temporary 'old_primrec'
blanchet
parents:
55574
diff
changeset
|
428 |
handle List.Empty => raise PRIMREC ("missing equations for function " ^ quote x, [])); |
54246
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
429 |
|
55772
367ec44763fd
correct most general type for mutual recursion when several identical types are involved
blanchet
parents:
55576
diff
changeset
|
430 |
val frees = map (fst #>> Binding.name_of #> Free) fixes; |
367ec44763fd
correct most general type for mutual recursion when several identical types are involved
blanchet
parents:
55576
diff
changeset
|
431 |
val has_call = exists_subterm (member (op =) frees); |
54246
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
432 |
val arg_Ts = map (#rec_type o hd) funs_data; |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
433 |
val res_Ts = map (#res_type o hd) funs_data; |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
434 |
val callssss = funs_data |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
435 |
|> map (partition_eq ((op =) o pairself #ctr)) |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
436 |
|> map (maps (map_filter (find_rec_calls has_call))); |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
437 |
|
55528
c367f4f3e5d4
have 'primrec_new' fall back on old 'primrec' when given old-style datatypes
blanchet
parents:
55527
diff
changeset
|
438 |
fun is_only_old_datatype (Type (s, _)) = |
55571 | 439 |
is_some (Datatype_Data.get_info thy s) andalso not (is_new_datatype lthy0 s) |
55528
c367f4f3e5d4
have 'primrec_new' fall back on old 'primrec' when given old-style datatypes
blanchet
parents:
55527
diff
changeset
|
440 |
| is_only_old_datatype _ = false; |
c367f4f3e5d4
have 'primrec_new' fall back on old 'primrec' when given old-style datatypes
blanchet
parents:
55527
diff
changeset
|
441 |
|
c367f4f3e5d4
have 'primrec_new' fall back on old 'primrec' when given old-style datatypes
blanchet
parents:
55527
diff
changeset
|
442 |
val _ = if exists is_only_old_datatype arg_Ts then raise OLD_PRIMREC () else (); |
54272
9d623cada37f
avoid subtle failure in the presence of top sort
blanchet
parents:
54256
diff
changeset
|
443 |
val _ = (case filter_out (fn (_, T) => Sign.of_sort thy (T, HOLogic.typeS)) (bs ~~ res_Ts) of |
9d623cada37f
avoid subtle failure in the presence of top sort
blanchet
parents:
54256
diff
changeset
|
444 |
[] => () |
55575
a5e33e18fb5c
moved 'primrec' up (for real this time) and removed temporary 'old_primrec'
blanchet
parents:
55574
diff
changeset
|
445 |
| (b, _) :: _ => raise PRIMREC ("type of " ^ Binding.print b ^ " contains top sort", [])); |
54272
9d623cada37f
avoid subtle failure in the presence of top sort
blanchet
parents:
54256
diff
changeset
|
446 |
|
55535
10194808430d
name derivations in 'primrec' for code extraction from proof terms
blanchet
parents:
55530
diff
changeset
|
447 |
val ((n2m, rec_specs, _, induct_thm, induct_thms), lthy) = |
55772
367ec44763fd
correct most general type for mutual recursion when several identical types are involved
blanchet
parents:
55576
diff
changeset
|
448 |
rec_specs_of bs arg_Ts res_Ts frees callssss lthy0; |
54246
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
449 |
|
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
450 |
val actual_nn = length funs_data; |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
451 |
|
55539
0819931d652d
simplified data structure by reducing the incidence of clumsy indices
blanchet
parents:
55538
diff
changeset
|
452 |
val ctrs = maps (map #ctr o #ctr_specs) rec_specs; |
0819931d652d
simplified data structure by reducing the incidence of clumsy indices
blanchet
parents:
55538
diff
changeset
|
453 |
val _ = |
54246
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
454 |
map (fn {ctr, user_eqn, ...} => member (op =) ctrs ctr orelse |
55575
a5e33e18fb5c
moved 'primrec' up (for real this time) and removed temporary 'old_primrec'
blanchet
parents:
55574
diff
changeset
|
455 |
raise PRIMREC ("argument " ^ quote (Syntax.string_of_term lthy ctr) ^ |
a5e33e18fb5c
moved 'primrec' up (for real this time) and removed temporary 'old_primrec'
blanchet
parents:
55574
diff
changeset
|
456 |
" is not a constructor in left-hand side", [user_eqn])) eqns_data; |
54246
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
457 |
|
55535
10194808430d
name derivations in 'primrec' for code extraction from proof terms
blanchet
parents:
55530
diff
changeset
|
458 |
val defs = build_defs lthy bs mxs funs_data rec_specs has_call; |
54246
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
459 |
|
55535
10194808430d
name derivations in 'primrec' for code extraction from proof terms
blanchet
parents:
55530
diff
changeset
|
460 |
fun prove lthy' def_thms' ({ctr_specs, nested_map_idents, nested_map_comps, ...} : rec_spec) |
54246
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
461 |
(fun_data : eqn_data list) = |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
462 |
let |
55535
10194808430d
name derivations in 'primrec' for code extraction from proof terms
blanchet
parents:
55530
diff
changeset
|
463 |
val js = |
10194808430d
name derivations in 'primrec' for code extraction from proof terms
blanchet
parents:
55530
diff
changeset
|
464 |
find_indices (op = o pairself (fn {fun_name, ctr, ...} => (fun_name, ctr))) |
10194808430d
name derivations in 'primrec' for code extraction from proof terms
blanchet
parents:
55530
diff
changeset
|
465 |
fun_data eqns_data; |
10194808430d
name derivations in 'primrec' for code extraction from proof terms
blanchet
parents:
55530
diff
changeset
|
466 |
|
54246
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
467 |
val def_thms = map (snd o snd) def_thms'; |
55535
10194808430d
name derivations in 'primrec' for code extraction from proof terms
blanchet
parents:
55530
diff
changeset
|
468 |
val simp_thms = finds (fn (x, y) => #ctr x = #ctr y) fun_data ctr_specs |
54246
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
469 |
|> fst |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
470 |
|> map_filter (try (fn (x, [y]) => |
55535
10194808430d
name derivations in 'primrec' for code extraction from proof terms
blanchet
parents:
55530
diff
changeset
|
471 |
(#fun_name x, #user_eqn x, length (#left_args x) + length (#right_args x), #rec_thm y))) |
10194808430d
name derivations in 'primrec' for code extraction from proof terms
blanchet
parents:
55530
diff
changeset
|
472 |
|> map2 (fn j => fn (fun_name, user_eqn, num_extra_args, rec_thm) => |
55772
367ec44763fd
correct most general type for mutual recursion when several identical types are involved
blanchet
parents:
55576
diff
changeset
|
473 |
mk_primrec_tac lthy' num_extra_args nested_map_idents nested_map_comps def_thms |
367ec44763fd
correct most general type for mutual recursion when several identical types are involved
blanchet
parents:
55576
diff
changeset
|
474 |
rec_thm |
55535
10194808430d
name derivations in 'primrec' for code extraction from proof terms
blanchet
parents:
55530
diff
changeset
|
475 |
|> K |> Goal.prove_sorry lthy' [] [] user_eqn |
10194808430d
name derivations in 'primrec' for code extraction from proof terms
blanchet
parents:
55530
diff
changeset
|
476 |
(* for code extraction from proof terms: *) |
10194808430d
name derivations in 'primrec' for code extraction from proof terms
blanchet
parents:
55530
diff
changeset
|
477 |
|> singleton (Proof_Context.export lthy' lthy) |
10194808430d
name derivations in 'primrec' for code extraction from proof terms
blanchet
parents:
55530
diff
changeset
|
478 |
|> Thm.name_derivation (Sign.full_name thy (Binding.name fun_name) ^ |
10194808430d
name derivations in 'primrec' for code extraction from proof terms
blanchet
parents:
55530
diff
changeset
|
479 |
Long_Name.separator ^ simpsN ^ |
10194808430d
name derivations in 'primrec' for code extraction from proof terms
blanchet
parents:
55530
diff
changeset
|
480 |
(if js = [0] then "" else "_" ^ string_of_int (j + 1)))) |
10194808430d
name derivations in 'primrec' for code extraction from proof terms
blanchet
parents:
55530
diff
changeset
|
481 |
js; |
54246
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
482 |
in |
55535
10194808430d
name derivations in 'primrec' for code extraction from proof terms
blanchet
parents:
55530
diff
changeset
|
483 |
(js, simp_thms) |
54246
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
484 |
end; |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
485 |
|
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
486 |
val notes = |
55482
61ffc2339a8c
removed assumption in 'primrec_new' that a given constructor can only occur once
blanchet
parents:
55480
diff
changeset
|
487 |
(if n2m then |
55575
a5e33e18fb5c
moved 'primrec' up (for real this time) and removed temporary 'old_primrec'
blanchet
parents:
55574
diff
changeset
|
488 |
map2 (fn name => fn thm => (name, inductN, [thm], [])) fun_names |
a5e33e18fb5c
moved 'primrec' up (for real this time) and removed temporary 'old_primrec'
blanchet
parents:
55574
diff
changeset
|
489 |
(take actual_nn induct_thms) |
55482
61ffc2339a8c
removed assumption in 'primrec_new' that a given constructor can only occur once
blanchet
parents:
55480
diff
changeset
|
490 |
else |
61ffc2339a8c
removed assumption in 'primrec_new' that a given constructor can only occur once
blanchet
parents:
55480
diff
changeset
|
491 |
[]) |
54246
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
492 |
|> map (fn (prefix, thmN, thms, attrs) => |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
493 |
((Binding.qualify true prefix (Binding.name thmN), attrs), [(thms, [])])); |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
494 |
|
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
495 |
val common_name = mk_common_name fun_names; |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
496 |
|
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
497 |
val common_notes = |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
498 |
(if n2m then [(inductN, [induct_thm], [])] else []) |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
499 |
|> map (fn (thmN, thms, attrs) => |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
500 |
((Binding.qualify true common_name (Binding.name thmN), attrs), [(thms, [])])); |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
501 |
in |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
502 |
(((fun_names, defs), |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
503 |
fn lthy => fn defs => |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
504 |
split_list (map2 (prove lthy defs) (take actual_nn rec_specs) funs_data)), |
55535
10194808430d
name derivations in 'primrec' for code extraction from proof terms
blanchet
parents:
55530
diff
changeset
|
505 |
lthy |> Local_Theory.notes (notes @ common_notes) |> snd) |
54246
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
506 |
end; |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
507 |
|
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
508 |
fun add_primrec_simple fixes ts lthy = |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
509 |
let |
55527 | 510 |
val (((names, defs), prove), lthy') = prepare_primrec fixes ts lthy |
55575
a5e33e18fb5c
moved 'primrec' up (for real this time) and removed temporary 'old_primrec'
blanchet
parents:
55574
diff
changeset
|
511 |
handle ERROR str => raise PRIMREC (str, []); |
54246
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
512 |
in |
55527 | 513 |
lthy' |
54246
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
514 |
|> fold_map Local_Theory.define defs |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
515 |
|-> (fn defs => `(fn lthy => (names, (map fst defs, prove lthy defs)))) |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
516 |
end |
55527 | 517 |
handle PRIMREC (str, eqns) => |
518 |
if null eqns then |
|
55530
3dfb724db099
renamed 'primrec_new' to 'primrec', overriding the old command (which it still uses as a fallback for old-style datatypes)
blanchet
parents:
55529
diff
changeset
|
519 |
error ("primrec error:\n " ^ str) |
55527 | 520 |
else |
55530
3dfb724db099
renamed 'primrec_new' to 'primrec', overriding the old command (which it still uses as a fallback for old-style datatypes)
blanchet
parents:
55529
diff
changeset
|
521 |
error ("primrec error:\n " ^ str ^ "\nin\n " ^ |
55527 | 522 |
space_implode "\n " (map (quote o Syntax.string_of_term lthy) eqns)); |
54246
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
523 |
|
55528
c367f4f3e5d4
have 'primrec_new' fall back on old 'primrec' when given old-style datatypes
blanchet
parents:
55527
diff
changeset
|
524 |
fun gen_primrec old_primrec prep_spec (raw_fixes : (binding * 'a option * mixfix) list) raw_spec |
c367f4f3e5d4
have 'primrec_new' fall back on old 'primrec' when given old-style datatypes
blanchet
parents:
55527
diff
changeset
|
525 |
lthy = |
54246
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
526 |
let |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
527 |
val d = duplicates (op =) (map (Binding.name_of o #1) raw_fixes) |
55575
a5e33e18fb5c
moved 'primrec' up (for real this time) and removed temporary 'old_primrec'
blanchet
parents:
55574
diff
changeset
|
528 |
val _ = null d orelse raise PRIMREC ("duplicate function name(s): " ^ commas d, []); |
54246
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
529 |
|
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
530 |
val (fixes, specs) = fst (prep_spec raw_fixes raw_spec lthy); |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
531 |
|
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
532 |
val mk_notes = |
55535
10194808430d
name derivations in 'primrec' for code extraction from proof terms
blanchet
parents:
55530
diff
changeset
|
533 |
flat ooo map3 (fn js => fn prefix => fn thms => |
54246
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
534 |
let |
55535
10194808430d
name derivations in 'primrec' for code extraction from proof terms
blanchet
parents:
55530
diff
changeset
|
535 |
val (bs, attrss) = map_split (fst o nth specs) js; |
54246
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
536 |
val notes = |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
537 |
map3 (fn b => fn attrs => fn thm => |
55464 | 538 |
((Binding.qualify false prefix b, code_nitpicksimp_simp_attrs @ attrs), |
539 |
[([thm], [])])) |
|
540 |
bs attrss thms; |
|
54246
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
541 |
in |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
542 |
((Binding.qualify true prefix (Binding.name simpsN), []), [(thms, [])]) :: notes |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
543 |
end); |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
544 |
in |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
545 |
lthy |
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
546 |
|> add_primrec_simple fixes (map snd specs) |
55535
10194808430d
name derivations in 'primrec' for code extraction from proof terms
blanchet
parents:
55530
diff
changeset
|
547 |
|-> (fn (names, (ts, (jss, simpss))) => |
54246
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
548 |
Spec_Rules.add Spec_Rules.Equational (ts, flat simpss) |
55535
10194808430d
name derivations in 'primrec' for code extraction from proof terms
blanchet
parents:
55530
diff
changeset
|
549 |
#> Local_Theory.notes (mk_notes jss names simpss) |
54246
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
550 |
#>> pair ts o map snd) |
55528
c367f4f3e5d4
have 'primrec_new' fall back on old 'primrec' when given old-style datatypes
blanchet
parents:
55527
diff
changeset
|
551 |
end |
c367f4f3e5d4
have 'primrec_new' fall back on old 'primrec' when given old-style datatypes
blanchet
parents:
55527
diff
changeset
|
552 |
handle OLD_PRIMREC () => old_primrec raw_fixes raw_spec lthy |>> apsnd single; |
54246
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
553 |
|
55528
c367f4f3e5d4
have 'primrec_new' fall back on old 'primrec' when given old-style datatypes
blanchet
parents:
55527
diff
changeset
|
554 |
val add_primrec = gen_primrec Primrec.add_primrec Specification.check_spec; |
c367f4f3e5d4
have 'primrec_new' fall back on old 'primrec' when given old-style datatypes
blanchet
parents:
55527
diff
changeset
|
555 |
val add_primrec_cmd = gen_primrec Primrec.add_primrec_cmd Specification.read_spec; |
54246
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
556 |
|
55535
10194808430d
name derivations in 'primrec' for code extraction from proof terms
blanchet
parents:
55530
diff
changeset
|
557 |
fun add_primrec_global fixes specs = |
10194808430d
name derivations in 'primrec' for code extraction from proof terms
blanchet
parents:
55530
diff
changeset
|
558 |
Named_Target.theory_init |
10194808430d
name derivations in 'primrec' for code extraction from proof terms
blanchet
parents:
55530
diff
changeset
|
559 |
#> add_primrec fixes specs |
10194808430d
name derivations in 'primrec' for code extraction from proof terms
blanchet
parents:
55530
diff
changeset
|
560 |
##> Local_Theory.exit_global; |
54246
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
561 |
|
55535
10194808430d
name derivations in 'primrec' for code extraction from proof terms
blanchet
parents:
55530
diff
changeset
|
562 |
fun add_primrec_overloaded ops fixes specs = |
10194808430d
name derivations in 'primrec' for code extraction from proof terms
blanchet
parents:
55530
diff
changeset
|
563 |
Overloading.overloading ops |
10194808430d
name derivations in 'primrec' for code extraction from proof terms
blanchet
parents:
55530
diff
changeset
|
564 |
#> add_primrec fixes specs |
10194808430d
name derivations in 'primrec' for code extraction from proof terms
blanchet
parents:
55530
diff
changeset
|
565 |
##> Local_Theory.exit_global; |
54246
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
566 |
|
55530
3dfb724db099
renamed 'primrec_new' to 'primrec', overriding the old command (which it still uses as a fallback for old-style datatypes)
blanchet
parents:
55529
diff
changeset
|
567 |
val _ = Outer_Syntax.local_theory @{command_spec "primrec"} |
55529 | 568 |
"define primitive recursive functions" |
569 |
(Parse.fixes -- Parse_Spec.where_alt_specs >> (snd oo uncurry add_primrec_cmd)); |
|
570 |
||
54246
8fdb4dc08ed1
split 'primrec_new' and 'primcorec' code (to ease bootstrapping, e.g. dependency on datatype 'String' in 'primcorec')
blanchet
parents:
diff
changeset
|
571 |
end; |