37 |
37 |
38 open Domain_Library; |
38 open Domain_Library; |
39 |
39 |
40 (* ----- general testing and preprocessing of constructor list -------------- *) |
40 (* ----- general testing and preprocessing of constructor list -------------- *) |
41 fun check_and_sort_domain |
41 fun check_and_sort_domain |
|
42 (arg_sort : bool -> sort) |
42 (dtnvs : (string * typ list) list) |
43 (dtnvs : (string * typ list) list) |
43 (cons'' : (binding * (bool * binding option * typ) list * mixfix) list list) |
44 (cons'' : (binding * (bool * binding option * typ) list * mixfix) list list) |
44 (thy : theory) |
45 (thy : theory) |
45 : ((string * typ list) * |
46 : ((string * typ list) * |
46 (binding * (bool * binding option * typ) list * mixfix) list) list = |
47 (binding * (bool * binding option * typ) list * mixfix) list) list = |
102 else error ("Direct recursion of type " ^ |
103 else error ("Direct recursion of type " ^ |
103 quote (string_of_typ thy t) ^ |
104 quote (string_of_typ thy t) ^ |
104 " with different arguments")) |
105 " with different arguments")) |
105 | analyse indirect (TVar _) = Imposs "extender:analyse"; |
106 | analyse indirect (TVar _) = Imposs "extender:analyse"; |
106 fun check_pcpo lazy T = |
107 fun check_pcpo lazy T = |
107 let val ok = if lazy then cpo_type else pcpo_type |
108 let val sort = arg_sort lazy in |
108 in if ok thy T then T |
109 if Sign.of_sort thy (T, sort) then T |
109 else error ("Constructor argument type is not of sort pcpo: " ^ |
110 else error ("Constructor argument type is not of sort " ^ |
110 string_of_typ thy T) |
111 Syntax.string_of_sort_global thy sort ^ ": " ^ |
|
112 string_of_typ thy T) |
111 end; |
113 end; |
112 fun analyse_arg (lazy, sel, T) = |
114 fun analyse_arg (lazy, sel, T) = |
113 (lazy, sel, check_pcpo lazy (analyse false T)); |
115 (lazy, sel, check_pcpo lazy (analyse false T)); |
114 fun analyse_con (b, args, mx) = (b, map analyse_arg args, mx); |
116 fun analyse_con (b, args, mx) = (b, map analyse_arg args, mx); |
115 in ((dname,distinct_typevars), map analyse_con cons') end; |
117 in ((dname,distinct_typevars), map analyse_con cons') end; |
122 Domain_Take_Proofs.iso_info list * Domain_Take_Proofs.take_induct_info; |
124 Domain_Take_Proofs.iso_info list * Domain_Take_Proofs.take_induct_info; |
123 |
125 |
124 fun gen_add_domain |
126 fun gen_add_domain |
125 (prep_typ : theory -> 'a -> typ) |
127 (prep_typ : theory -> 'a -> typ) |
126 (add_isos : (binding * mixfix * (typ * typ)) list -> theory -> info * theory) |
128 (add_isos : (binding * mixfix * (typ * typ)) list -> theory -> info * theory) |
|
129 (arg_sort : bool -> sort) |
127 (comp_dbind : binding) |
130 (comp_dbind : binding) |
128 (eqs''' : ((string * string option) list * binding * mixfix * |
131 (eqs''' : ((string * string option) list * binding * mixfix * |
129 (binding * (bool * binding option * 'a) list * mixfix) list) list) |
132 (binding * (bool * binding option * 'a) list * mixfix) list) list) |
130 (thy : theory) = |
133 (thy : theory) = |
131 let |
134 let |
159 map (map (upd_second (map (upd_third (prep_typ tmp_thy))))) cons'''; |
162 map (map (upd_second (map (upd_third (prep_typ tmp_thy))))) cons'''; |
160 val dtnvs' : (string * typ list) list = |
163 val dtnvs' : (string * typ list) list = |
161 map (fn (dname,vs,mx) => (Sign.full_name thy dname,vs)) dtnvs; |
164 map (fn (dname,vs,mx) => (Sign.full_name thy dname,vs)) dtnvs; |
162 val eqs' : ((string * typ list) * |
165 val eqs' : ((string * typ list) * |
163 (binding * (bool * binding option * typ) list * mixfix) list) list = |
166 (binding * (bool * binding option * typ) list * mixfix) list) list = |
164 check_and_sort_domain dtnvs' cons'' tmp_thy; |
167 check_and_sort_domain arg_sort dtnvs' cons'' tmp_thy; |
165 val dts : typ list = map (Type o fst) eqs'; |
168 val dts : typ list = map (Type o fst) eqs'; |
166 |
169 |
167 fun mk_arg_typ (lazy, dest_opt, T) = if lazy then mk_uT T else T; |
170 fun mk_arg_typ (lazy, dest_opt, T) = if lazy then mk_uT T else T; |
168 fun mk_con_typ (bind, args, mx) = |
171 fun mk_con_typ (bind, args, mx) = |
169 if null args then oneT else foldr1 mk_sprodT (map mk_arg_typ args); |
172 if null args then oneT else foldr1 mk_sprodT (map mk_arg_typ args); |
207 in (map (fst o dest_TFree) vs, dbind, mx, rhsT, NONE) end; |
210 in (map (fst o dest_TFree) vs, dbind, mx, rhsT, NONE) end; |
208 in |
211 in |
209 Domain_Isomorphism.domain_isomorphism (map prep spec) |
212 Domain_Isomorphism.domain_isomorphism (map prep spec) |
210 end; |
213 end; |
211 |
214 |
|
215 fun pcpo_arg lazy = if lazy then @{sort cpo} else @{sort pcpo}; |
|
216 fun rep_arg lazy = @{sort rep}; |
|
217 |
212 val add_domain = |
218 val add_domain = |
213 gen_add_domain Sign.certify_typ Domain_Axioms.add_axioms; |
219 gen_add_domain Sign.certify_typ Domain_Axioms.add_axioms pcpo_arg; |
214 |
220 |
215 val add_new_domain = |
221 val add_new_domain = |
216 gen_add_domain Sign.certify_typ define_isos; |
222 gen_add_domain Sign.certify_typ define_isos rep_arg; |
217 |
223 |
218 val add_domain_cmd = |
224 val add_domain_cmd = |
219 gen_add_domain Syntax.read_typ_global Domain_Axioms.add_axioms; |
225 gen_add_domain Syntax.read_typ_global Domain_Axioms.add_axioms pcpo_arg; |
220 |
226 |
221 val add_new_domain_cmd = |
227 val add_new_domain_cmd = |
222 gen_add_domain Syntax.read_typ_global define_isos; |
228 gen_add_domain Syntax.read_typ_global define_isos rep_arg; |
223 |
229 |
224 |
230 |
225 (** outer syntax **) |
231 (** outer syntax **) |
226 |
232 |
227 val _ = Keyword.keyword "lazy"; |
233 val _ = Keyword.keyword "lazy"; |