95 val (_, tenv) = fo_match ctxt call pat; |
95 val (_, tenv) = fo_match ctxt call pat; |
96 in |
96 in |
97 (map0, Vartab.fold_rev (fn (_, (_, f)) => cons f) tenv []) |
97 (map0, Vartab.fold_rev (fn (_, (_, f)) => cons f) tenv []) |
98 end; |
98 end; |
99 |
99 |
100 fun dest_abs_or_applied_map_or_ctr _ _ (Abs (_, _, t)) = (Term.dummy, [t]) |
100 fun dest_abs_or_applied_map _ _ (Abs (_, _, t)) = (Term.dummy, [t]) |
101 | dest_abs_or_applied_map_or_ctr ctxt s (t as t1 $ _) = |
101 | dest_abs_or_applied_map ctxt s (t1 $ _) = dest_map ctxt s t1; |
102 (case try (dest_map ctxt s) t1 of |
|
103 SOME res => res |
|
104 | NONE => |
|
105 let |
|
106 val thy = Proof_Context.theory_of ctxt; |
|
107 val map_thms = flat (#mapss (the (fp_sugar_of ctxt s))); |
|
108 val map_thms' = map (fn thm => thm RS sym RS eq_reflection) map_thms; |
|
109 val t' = Raw_Simplifier.rewrite_term thy map_thms' [] t; |
|
110 in |
|
111 if t aconv t' then raise Fail "dest_abs_or_applied_map_or_ctr" |
|
112 else dest_map ctxt s (fst (dest_comb t')) |
|
113 end); |
|
114 |
102 |
115 fun map_partition f xs = |
103 fun map_partition f xs = |
116 fold_rev (fn x => fn (ys, (good, bad)) => |
104 fold_rev (fn x => fn (ys, (good, bad)) => |
117 case f x of SOME y => (y :: ys, (x :: good, bad)) | NONE => (ys, (good, x :: bad))) |
105 case f x of SOME y => (y :: ys, (x :: good, bad)) | NONE => (ys, (good, x :: bad))) |
118 xs ([], ([], [])); |
106 xs ([], ([], [])); |
177 Type (s, map2 freeze_fpTs (flatten_type_args_of_bnf (the (bnf_of no_defs_lthy s)) [] |
165 Type (s, map2 freeze_fpTs (flatten_type_args_of_bnf (the (bnf_of no_defs_lthy s)) [] |
178 (transpose callss)) Ts)) |
166 (transpose callss)) Ts)) |
179 and freeze_fpTs calls (T as Type (s, Ts)) = |
167 and freeze_fpTs calls (T as Type (s, Ts)) = |
180 (case map_partition (try (snd o dest_map no_defs_lthy s)) calls of |
168 (case map_partition (try (snd o dest_map no_defs_lthy s)) calls of |
181 ([], _) => |
169 ([], _) => |
182 (case map_partition (try (snd o dest_abs_or_applied_map_or_ctr no_defs_lthy s)) calls of |
170 (case map_partition (try (snd o dest_abs_or_applied_map no_defs_lthy s)) calls of |
183 ([], _) => freeze_fpTs_simple T |
171 ([], _) => freeze_fpTs_simple T |
184 | callsp => freeze_fpTs_map callsp s Ts) |
172 | callsp => freeze_fpTs_map callsp s Ts) |
185 | callsp => freeze_fpTs_map callsp s Ts) |
173 | callsp => freeze_fpTs_map callsp s Ts) |
186 | freeze_fpTs _ T = T; |
174 | freeze_fpTs _ T = T; |
187 |
175 |