62 (case pairself Term.head_of (rhs, rhs') of |
62 (case pairself Term.head_of (rhs, rhs') of |
63 (Const (a, _), Const (a', _)) => a = a' |
63 (Const (a, _), Const (a', _)) => a = a' |
64 | _ => false); |
64 | _ => false); |
65 in |
65 in |
66 eq_heads ? (Context.mapping_result |
66 eq_heads ? (Context.mapping_result |
67 (Sign.add_abbrev Syntax.internalM arg') (ProofContext.add_abbrev Syntax.internalM arg') |
67 (Sign.add_abbrev Syntax.internalM [] arg') (ProofContext.add_abbrev Syntax.internalM [] arg') |
68 #-> (fn (lhs, _) => |
68 #-> (fn (lhs, _) => |
69 Term.equiv_types (rhs, rhs') ? |
69 Term.equiv_types (rhs, rhs') ? |
70 Morphism.form (ProofContext.target_notation prmode [(lhs, mx)]))) |
70 Morphism.form (ProofContext.target_notation prmode [(lhs, mx)]))) |
71 end; |
71 end; |
72 |
72 |
73 fun internal_abbrev prmode ((c, mx), t) = |
73 fun internal_abbrev prmode ((c, mx), t) lthy = lthy |
74 (* FIXME really permissive *) |
74 (* FIXME really permissive *) |
75 LocalTheory.term_syntax (perhaps o try o target_abbrev prmode ((c, mx), t)) |
75 |> LocalTheory.term_syntax (perhaps o try o target_abbrev prmode ((c, mx), t)) |
76 #> ProofContext.add_abbrev Syntax.internalM (c, t) #> snd; |
76 |> ProofContext.add_abbrev Syntax.internalM (ContextPosition.properties_of lthy) (c, t) |
|
77 |> snd; |
77 |
78 |
78 fun consts is_loc some_class depends decls lthy = |
79 fun consts is_loc some_class depends decls lthy = |
79 let |
80 let |
80 val xs = filter depends (#1 (ProofContext.inferred_fixes (LocalTheory.target_of lthy))); |
81 val xs = filter depends (#1 (ProofContext.inferred_fixes (LocalTheory.target_of lthy))); |
81 |
82 |
82 fun const ((c, T), mx) thy = |
83 fun const ((c, T), mx) thy = |
83 let |
84 let |
84 val U = map #2 xs ---> T; |
85 val U = map #2 xs ---> T; |
85 val t = Term.list_comb (Const (Sign.full_name thy c, U), map Free xs); |
86 val t = Term.list_comb (Const (Sign.full_name thy c, U), map Free xs); |
86 val (mx1, mx2) = Class.fork_mixfix is_loc some_class mx; |
87 val (mx1, mx2) = Class.fork_mixfix is_loc some_class mx; |
87 val thy' = Sign.add_consts_authentic [(c, U, mx1)] thy; |
88 val thy' = Sign.add_consts_authentic (ContextPosition.properties_of lthy) [(c, U, mx1)] thy; |
88 in (((c, mx2), t), thy') end; |
89 in (((c, mx2), t), thy') end; |
89 |
90 |
90 fun const_class (SOME class) ((c, _), mx) (_, t) = |
91 fun const_class (SOME class) ((c, _), mx) (_, t) = |
91 Class.add_const_in_class class ((c, t), mx) |
92 Class.add_const_in_class class ((c, t), mx) |
92 | const_class NONE _ _ = I; |
93 | const_class NONE _ _ = I; |
149 val xs = map Free (occ_params target [t]); |
150 val xs = map Free (occ_params target [t]); |
150 val u = fold_rev Term.lambda xs t; |
151 val u = fold_rev Term.lambda xs t; |
151 val U = Term.fastype_of u; |
152 val U = Term.fastype_of u; |
152 val u' = singleton (Variable.export_terms (Variable.declare_term u target) thy_ctxt) u; |
153 val u' = singleton (Variable.export_terms (Variable.declare_term u target) thy_ctxt) u; |
153 |
154 |
154 val ((lhs as Const (full_c, _), rhs), lthy1) = lthy |
155 val ((lhs as Const (full_c, _), rhs), lthy1) = lthy |> LocalTheory.theory_result |
155 |> LocalTheory.theory_result (Sign.add_abbrev (#1 prmode) (c, u')); |
156 (Sign.add_abbrev (#1 prmode) (ContextPosition.properties_of lthy) (c, u')); |
156 val (mx1, mx2) = Class.fork_mixfix is_loc some_class mx; |
157 val (mx1, mx2) = Class.fork_mixfix is_loc some_class mx; |
157 in |
158 in |
158 lthy1 |
159 lthy1 |
159 |> LocalTheory.theory (Sign.add_notation prmode [(lhs, mx1)]) |
160 |> LocalTheory.theory (Sign.add_notation prmode [(lhs, mx1)]) |
160 |> is_loc ? internal_abbrev prmode ((c, mx2), Term.list_comb (Const (full_c, U), xs)) |
161 |> is_loc ? internal_abbrev prmode ((c, mx2), Term.list_comb (Const (full_c, U), xs)) |