16 liftdefl_def : thm, |
16 liftdefl_def : thm, |
17 DEFL : thm |
17 DEFL : thm |
18 } |
18 } |
19 |
19 |
20 val add_domaindef: binding * (string * sort) list * mixfix -> |
20 val add_domaindef: binding * (string * sort) list * mixfix -> |
21 term -> (binding * binding) option -> theory -> |
21 term -> Typedef.bindings option -> theory -> |
22 (Typedef.info * Cpodef.cpo_info * Cpodef.pcpo_info * rep_info) * theory |
22 (Typedef.info * Cpodef.cpo_info * Cpodef.pcpo_info * rep_info) * theory |
23 |
23 |
24 val domaindef_cmd: (binding * (string * string option) list * mixfix) * string |
24 val domaindef_cmd: (binding * (string * string option) list * mixfix) * string |
25 * (binding * binding) option -> theory -> theory |
25 * Typedef.bindings option -> theory -> theory |
26 end |
26 end |
27 |
27 |
28 structure Domaindef : DOMAINDEF = |
28 structure Domaindef : DOMAINDEF = |
29 struct |
29 struct |
30 |
30 |
78 |
78 |
79 fun gen_add_domaindef |
79 fun gen_add_domaindef |
80 (prep_term: Proof.context -> 'a -> term) |
80 (prep_term: Proof.context -> 'a -> term) |
81 (typ as (tname, raw_args, _) : binding * (string * sort) list * mixfix) |
81 (typ as (tname, raw_args, _) : binding * (string * sort) list * mixfix) |
82 (raw_defl: 'a) |
82 (raw_defl: 'a) |
83 (opt_morphs: (binding * binding) option) |
83 (opt_bindings: Typedef.bindings option) |
84 (thy: theory) |
84 (thy: theory) |
85 : (Typedef.info * Cpodef.cpo_info * Cpodef.pcpo_info * rep_info) * theory = |
85 : (Typedef.info * Cpodef.cpo_info * Cpodef.pcpo_info * rep_info) * theory = |
86 let |
86 let |
87 (*rhs*) |
87 (*rhs*) |
88 val tmp_ctxt = |
88 val tmp_ctxt = |
98 (*lhs*) |
98 (*lhs*) |
99 val lhs_tfrees = map (Proof_Context.check_tfree tmp_ctxt) raw_args |
99 val lhs_tfrees = map (Proof_Context.check_tfree tmp_ctxt) raw_args |
100 val full_tname = Sign.full_name thy tname |
100 val full_tname = Sign.full_name thy tname |
101 val newT = Type (full_tname, map TFree lhs_tfrees) |
101 val newT = Type (full_tname, map TFree lhs_tfrees) |
102 |
102 |
103 (*morphisms*) |
|
104 val morphs = opt_morphs |
|
105 |> the_default (Binding.prefix_name "Rep_" tname, Binding.prefix_name "Abs_" tname) |
|
106 |
|
107 (*set*) |
103 (*set*) |
108 val set = @{term "defl_set :: udom defl => udom set"} $ defl |
104 val set = @{term "defl_set :: udom defl => udom set"} $ defl |
109 |
105 |
110 (*pcpodef*) |
106 (*pcpodef*) |
111 fun tac1 ctxt = resolve_tac ctxt @{thms defl_set_bottom} 1 |
107 fun tac1 ctxt = resolve_tac ctxt @{thms defl_set_bottom} 1 |
112 fun tac2 ctxt = resolve_tac ctxt @{thms adm_defl_set} 1 |
108 fun tac2 ctxt = resolve_tac ctxt @{thms adm_defl_set} 1 |
113 val ((info, cpo_info, pcpo_info), thy) = thy |
109 val ((info, cpo_info, pcpo_info), thy) = thy |
114 |> Cpodef.add_pcpodef typ set (SOME morphs) (tac1, tac2) |
110 |> Cpodef.add_pcpodef typ set opt_bindings (tac1, tac2) |
115 |
111 |
116 (*definitions*) |
112 (*definitions*) |
117 val Rep_const = Const (#Rep_name (#1 info), newT --> udomT) |
113 val Rep_const = Const (#Rep_name (#1 info), newT --> udomT) |
118 val Abs_const = Const (#Abs_name (#1 info), udomT --> newT) |
114 val Abs_const = Const (#Abs_name (#1 info), udomT --> newT) |
119 val emb_eqn = Logic.mk_equals (emb_const newT, cabs_const (newT, udomT) $ Rep_const) |
115 val emb_eqn = Logic.mk_equals (emb_const newT, cabs_const (newT, udomT) $ Rep_const) |
185 ((info, cpo_info, pcpo_info, rep_info), thy) |
181 ((info, cpo_info, pcpo_info, rep_info), thy) |
186 end |
182 end |
187 handle ERROR msg => |
183 handle ERROR msg => |
188 cat_error msg ("The error(s) above occurred in domaindef " ^ Binding.print tname) |
184 cat_error msg ("The error(s) above occurred in domaindef " ^ Binding.print tname) |
189 |
185 |
190 fun add_domaindef typ defl opt_morphs thy = |
186 fun add_domaindef typ defl opt_bindings thy = |
191 gen_add_domaindef Syntax.check_term typ defl opt_morphs thy |
187 gen_add_domaindef Syntax.check_term typ defl opt_bindings thy |
192 |
188 |
193 fun domaindef_cmd ((b, raw_args, mx), A, morphs) thy = |
189 fun domaindef_cmd ((b, raw_args, mx), A, morphs) thy = |
194 let |
190 let |
195 val ctxt = Proof_Context.init_global thy |
191 val ctxt = Proof_Context.init_global thy |
196 val args = map (apsnd (Typedecl.read_constraint ctxt)) raw_args |
192 val args = map (apsnd (Typedecl.read_constraint ctxt)) raw_args |
197 in snd (gen_add_domaindef Syntax.read_term (b, args, mx) A morphs thy) end |
193 in snd (gen_add_domaindef Syntax.read_term (b, args, mx) A morphs thy) end |
198 |
194 |
199 |
195 |
200 (** outer syntax **) |
196 (** outer syntax **) |
201 |
197 |
202 val domaindef_decl = |
|
203 (Parse.type_args_constrained -- Parse.binding) -- |
|
204 Parse.opt_mixfix -- (@{keyword "="} |-- Parse.term) -- |
|
205 Scan.option |
|
206 (@{keyword "morphisms"} |-- Parse.!!! (Parse.binding -- Parse.binding)) |
|
207 |
|
208 fun mk_domaindef (((((args, t)), mx), A), morphs) = |
|
209 domaindef_cmd ((t, args, mx), A, morphs) |
|
210 |
|
211 val _ = |
198 val _ = |
212 Outer_Syntax.command @{command_keyword domaindef} "HOLCF definition of domains from deflations" |
199 Outer_Syntax.command @{command_keyword domaindef} "HOLCF definition of domains from deflations" |
213 (domaindef_decl >> (Toplevel.theory o mk_domaindef)) |
200 ((Parse.type_args_constrained -- Parse.binding) -- |
|
201 Parse.opt_mixfix -- (@{keyword "="} |-- Parse.term) -- |
|
202 Scan.option |
|
203 (@{keyword "morphisms"} |-- Parse.!!! (Parse.binding -- Parse.binding)) >> |
|
204 (fn (((((args, t)), mx), A), morphs) => |
|
205 Toplevel.theory (domaindef_cmd ((t, args, mx), A, SOME (Typedef.make_morphisms t morphs))))); |
214 |
206 |
215 end |
207 end |