author | huffman |
Mon, 12 Apr 2010 16:04:32 -0700 | |
changeset 36118 | 413d6d1f0f6e |
parent 36117 | 01a9db7382f5 |
child 36119 | ff605b8fdfdb |
permissions | -rw-r--r-- |
32126 | 1 |
(* Title: HOLCF/Tools/Domain/domain_extender.ML |
23152 | 2 |
Author: David von Oheimb |
35794 | 3 |
Author: Brian Huffman |
23152 | 4 |
|
5 |
Theory extender for domain command, including theory syntax. |
|
6 |
*) |
|
7 |
||
8 |
signature DOMAIN_EXTENDER = |
|
9 |
sig |
|
33796 | 10 |
val add_domain_cmd: |
35774 | 11 |
binding -> |
33796 | 12 |
((string * string option) list * binding * mixfix * |
13 |
(binding * (bool * binding option * string) list * mixfix) list) list |
|
14 |
-> theory -> theory |
|
15 |
||
16 |
val add_domain: |
|
35774 | 17 |
binding -> |
33796 | 18 |
((string * string option) list * binding * mixfix * |
19 |
(binding * (bool * binding option * typ) list * mixfix) list) list |
|
20 |
-> theory -> theory |
|
33798
46cbbcbd4e68
clean up indentation; add 'definitional' option flag
huffman
parents:
33796
diff
changeset
|
21 |
|
46cbbcbd4e68
clean up indentation; add 'definitional' option flag
huffman
parents:
33796
diff
changeset
|
22 |
val add_new_domain_cmd: |
35774 | 23 |
binding -> |
33798
46cbbcbd4e68
clean up indentation; add 'definitional' option flag
huffman
parents:
33796
diff
changeset
|
24 |
((string * string option) list * binding * mixfix * |
46cbbcbd4e68
clean up indentation; add 'definitional' option flag
huffman
parents:
33796
diff
changeset
|
25 |
(binding * (bool * binding option * string) list * mixfix) list) list |
46cbbcbd4e68
clean up indentation; add 'definitional' option flag
huffman
parents:
33796
diff
changeset
|
26 |
-> theory -> theory |
46cbbcbd4e68
clean up indentation; add 'definitional' option flag
huffman
parents:
33796
diff
changeset
|
27 |
|
46cbbcbd4e68
clean up indentation; add 'definitional' option flag
huffman
parents:
33796
diff
changeset
|
28 |
val add_new_domain: |
35774 | 29 |
binding -> |
33798
46cbbcbd4e68
clean up indentation; add 'definitional' option flag
huffman
parents:
33796
diff
changeset
|
30 |
((string * string option) list * binding * mixfix * |
46cbbcbd4e68
clean up indentation; add 'definitional' option flag
huffman
parents:
33796
diff
changeset
|
31 |
(binding * (bool * binding option * typ) list * mixfix) list) list |
46cbbcbd4e68
clean up indentation; add 'definitional' option flag
huffman
parents:
33796
diff
changeset
|
32 |
-> theory -> theory |
23152 | 33 |
end; |
34 |
||
31023 | 35 |
structure Domain_Extender :> DOMAIN_EXTENDER = |
23152 | 36 |
struct |
37 |
||
38 |
open Domain_Library; |
|
39 |
||
40 |
(* ----- general testing and preprocessing of constructor list -------------- *) |
|
30919
dcf8a7a66bd1
make domain package ML interface more consistent with datatype package; use binding instead of bstring
huffman
parents:
30916
diff
changeset
|
41 |
fun check_and_sort_domain |
33798
46cbbcbd4e68
clean up indentation; add 'definitional' option flag
huffman
parents:
33796
diff
changeset
|
42 |
(definitional : bool) |
33796 | 43 |
(dtnvs : (string * typ list) list) |
44 |
(cons'' : (binding * (bool * binding option * typ) list * mixfix) list list) |
|
33798
46cbbcbd4e68
clean up indentation; add 'definitional' option flag
huffman
parents:
33796
diff
changeset
|
45 |
(thy : theory) |
31288 | 46 |
: ((string * typ list) * |
47 |
(binding * (bool * binding option * typ) list * mixfix) list) list = |
|
33796 | 48 |
let |
33798
46cbbcbd4e68
clean up indentation; add 'definitional' option flag
huffman
parents:
33796
diff
changeset
|
49 |
val defaultS = Sign.defaultS thy; |
33796 | 50 |
|
51 |
val test_dupl_typs = |
|
52 |
case duplicates (op =) (map fst dtnvs) of |
|
53 |
[] => false | dups => error ("Duplicate types: " ^ commas_quote dups); |
|
54 |
||
55 |
val all_cons = map (Binding.name_of o first) (flat cons''); |
|
56 |
val test_dupl_cons = |
|
57 |
case duplicates (op =) all_cons of |
|
58 |
[] => false | dups => error ("Duplicate constructors: " |
|
59 |
^ commas_quote dups); |
|
60 |
val all_sels = |
|
61 |
(map Binding.name_of o map_filter second o maps second) (flat cons''); |
|
62 |
val test_dupl_sels = |
|
63 |
case duplicates (op =) all_sels of |
|
64 |
[] => false | dups => error("Duplicate selectors: "^commas_quote dups); |
|
65 |
||
66 |
fun test_dupl_tvars s = |
|
67 |
case duplicates (op =) (map(fst o dest_TFree)s) of |
|
68 |
[] => false | dups => error("Duplicate type arguments: " |
|
69 |
^commas_quote dups); |
|
70 |
val test_dupl_tvars' = exists test_dupl_tvars (map snd dtnvs); |
|
71 |
||
72 |
(* test for free type variables, illegal sort constraints on rhs, |
|
73 |
non-pcpo-types and invalid use of recursive type; |
|
74 |
replace sorts in type variables on rhs *) |
|
75 |
fun analyse_equation ((dname,typevars),cons') = |
|
76 |
let |
|
77 |
val tvars = map dest_TFree typevars; |
|
78 |
val distinct_typevars = map TFree tvars; |
|
79 |
fun rm_sorts (TFree(s,_)) = TFree(s,[]) |
|
80 |
| rm_sorts (Type(s,ts)) = Type(s,remove_sorts ts) |
|
81 |
| rm_sorts (TVar(s,_)) = TVar(s,[]) |
|
82 |
and remove_sorts l = map rm_sorts l; |
|
35525 | 83 |
val indirect_ok = |
84 |
[@{type_name "*"}, @{type_name cfun}, @{type_name ssum}, |
|
85 |
@{type_name sprod}, @{type_name u}]; |
|
33796 | 86 |
fun analyse indirect (TFree(v,s)) = |
87 |
(case AList.lookup (op =) tvars v of |
|
88 |
NONE => error ("Free type variable " ^ quote v ^ " on rhs.") |
|
89 |
| SOME sort => if eq_set (op =) (s, defaultS) orelse |
|
90 |
eq_set (op =) (s, sort) |
|
91 |
then TFree(v,sort) |
|
92 |
else error ("Inconsistent sort constraint" ^ |
|
93 |
" for type variable " ^ quote v)) |
|
94 |
| analyse indirect (t as Type(s,typl)) = |
|
95 |
(case AList.lookup (op =) dtnvs s of |
|
96 |
NONE => |
|
33798
46cbbcbd4e68
clean up indentation; add 'definitional' option flag
huffman
parents:
33796
diff
changeset
|
97 |
if definitional orelse s mem indirect_ok |
33796 | 98 |
then Type(s,map (analyse false) typl) |
99 |
else Type(s,map (analyse true) typl) |
|
100 |
| SOME typevars => |
|
101 |
if indirect |
|
102 |
then error ("Indirect recursion of type " ^ |
|
33798
46cbbcbd4e68
clean up indentation; add 'definitional' option flag
huffman
parents:
33796
diff
changeset
|
103 |
quote (string_of_typ thy t)) |
33796 | 104 |
else if dname <> s orelse |
105 |
(** BUG OR FEATURE?: |
|
106 |
mutual recursion may use different arguments **) |
|
107 |
remove_sorts typevars = remove_sorts typl |
|
108 |
then Type(s,map (analyse true) typl) |
|
109 |
else error ("Direct recursion of type " ^ |
|
33798
46cbbcbd4e68
clean up indentation; add 'definitional' option flag
huffman
parents:
33796
diff
changeset
|
110 |
quote (string_of_typ thy t) ^ |
33796 | 111 |
" with different arguments")) |
112 |
| analyse indirect (TVar _) = Imposs "extender:analyse"; |
|
113 |
fun check_pcpo lazy T = |
|
114 |
let val ok = if lazy then cpo_type else pcpo_type |
|
33798
46cbbcbd4e68
clean up indentation; add 'definitional' option flag
huffman
parents:
33796
diff
changeset
|
115 |
in if ok thy T then T |
33796 | 116 |
else error ("Constructor argument type is not of sort pcpo: " ^ |
33798
46cbbcbd4e68
clean up indentation; add 'definitional' option flag
huffman
parents:
33796
diff
changeset
|
117 |
string_of_typ thy T) |
33796 | 118 |
end; |
119 |
fun analyse_arg (lazy, sel, T) = |
|
120 |
(lazy, sel, check_pcpo lazy (analyse false T)); |
|
121 |
fun analyse_con (b, args, mx) = (b, map analyse_arg args, mx); |
|
122 |
in ((dname,distinct_typevars), map analyse_con cons') end; |
|
123 |
in ListPair.map analyse_equation (dtnvs,cons'') |
|
124 |
end; (* let *) |
|
23152 | 125 |
|
126 |
(* ----- calls for building new thy and thms -------------------------------- *) |
|
127 |
||
36118
413d6d1f0f6e
share more code between definitional and axiomatic domain packages
huffman
parents:
36117
diff
changeset
|
128 |
type info = |
413d6d1f0f6e
share more code between definitional and axiomatic domain packages
huffman
parents:
36117
diff
changeset
|
129 |
Domain_Take_Proofs.iso_info list * Domain_Take_Proofs.take_induct_info; |
413d6d1f0f6e
share more code between definitional and axiomatic domain packages
huffman
parents:
36117
diff
changeset
|
130 |
|
30919
dcf8a7a66bd1
make domain package ML interface more consistent with datatype package; use binding instead of bstring
huffman
parents:
30916
diff
changeset
|
131 |
fun gen_add_domain |
33796 | 132 |
(prep_typ : theory -> 'a -> typ) |
36118
413d6d1f0f6e
share more code between definitional and axiomatic domain packages
huffman
parents:
36117
diff
changeset
|
133 |
(add_isos : (binding * mixfix * (typ * typ)) list -> theory -> info * theory) |
35774 | 134 |
(comp_dbind : binding) |
33798
46cbbcbd4e68
clean up indentation; add 'definitional' option flag
huffman
parents:
33796
diff
changeset
|
135 |
(eqs''' : ((string * string option) list * binding * mixfix * |
46cbbcbd4e68
clean up indentation; add 'definitional' option flag
huffman
parents:
33796
diff
changeset
|
136 |
(binding * (bool * binding option * 'a) list * mixfix) list) list) |
35516 | 137 |
(thy : theory) = |
33798
46cbbcbd4e68
clean up indentation; add 'definitional' option flag
huffman
parents:
33796
diff
changeset
|
138 |
let |
35520 | 139 |
val dtnvs : (binding * typ list * mixfix) list = |
140 |
let |
|
141 |
fun readS (SOME s) = Syntax.read_sort_global thy s |
|
142 |
| readS NONE = Sign.defaultS thy; |
|
143 |
fun readTFree (a, s) = TFree (a, readS s); |
|
144 |
in |
|
145 |
map (fn (vs,dname:binding,mx,_) => |
|
146 |
(dname, map readTFree vs, mx)) eqs''' |
|
147 |
end; |
|
33798
46cbbcbd4e68
clean up indentation; add 'definitional' option flag
huffman
parents:
33796
diff
changeset
|
148 |
|
46cbbcbd4e68
clean up indentation; add 'definitional' option flag
huffman
parents:
33796
diff
changeset
|
149 |
fun thy_type (dname,tvars,mx) = (dname, length tvars, mx); |
46cbbcbd4e68
clean up indentation; add 'definitional' option flag
huffman
parents:
33796
diff
changeset
|
150 |
fun thy_arity (dname,tvars,mx) = |
35516 | 151 |
(Sign.full_name thy dname, map (snd o dest_TFree) tvars, @{sort rep}); |
33798
46cbbcbd4e68
clean up indentation; add 'definitional' option flag
huffman
parents:
33796
diff
changeset
|
152 |
|
46cbbcbd4e68
clean up indentation; add 'definitional' option flag
huffman
parents:
33796
diff
changeset
|
153 |
(* this theory is used just for parsing and error checking *) |
35516 | 154 |
val tmp_thy = thy |
33798
46cbbcbd4e68
clean up indentation; add 'definitional' option flag
huffman
parents:
33796
diff
changeset
|
155 |
|> Theory.copy |
46cbbcbd4e68
clean up indentation; add 'definitional' option flag
huffman
parents:
33796
diff
changeset
|
156 |
|> Sign.add_types (map thy_type dtnvs) |
46cbbcbd4e68
clean up indentation; add 'definitional' option flag
huffman
parents:
33796
diff
changeset
|
157 |
|> fold (AxClass.axiomatize_arity o thy_arity) dtnvs; |
46cbbcbd4e68
clean up indentation; add 'definitional' option flag
huffman
parents:
33796
diff
changeset
|
158 |
|
35776
b0bc15d8ad3b
pass domain binding as argument to Domain_Theorems.theorems; proper qualified bindings for theorem names
huffman
parents:
35775
diff
changeset
|
159 |
val dbinds : binding list = |
b0bc15d8ad3b
pass domain binding as argument to Domain_Theorems.theorems; proper qualified bindings for theorem names
huffman
parents:
35775
diff
changeset
|
160 |
map (fn (_,dbind,_,_) => dbind) eqs'''; |
35520 | 161 |
val cons''' : |
162 |
(binding * (bool * binding option * 'a) list * mixfix) list list = |
|
163 |
map (fn (_,_,_,cons) => cons) eqs'''; |
|
164 |
val cons'' : |
|
165 |
(binding * (bool * binding option * typ) list * mixfix) list list = |
|
166 |
map (map (upd_second (map (upd_third (prep_typ tmp_thy))))) cons'''; |
|
33798
46cbbcbd4e68
clean up indentation; add 'definitional' option flag
huffman
parents:
33796
diff
changeset
|
167 |
val dtnvs' : (string * typ list) list = |
35520 | 168 |
map (fn (dname,vs,mx) => (Sign.full_name thy dname,vs)) dtnvs; |
33798
46cbbcbd4e68
clean up indentation; add 'definitional' option flag
huffman
parents:
33796
diff
changeset
|
169 |
val eqs' : ((string * typ list) * |
46cbbcbd4e68
clean up indentation; add 'definitional' option flag
huffman
parents:
33796
diff
changeset
|
170 |
(binding * (bool * binding option * typ) list * mixfix) list) list = |
35520 | 171 |
check_and_sort_domain true dtnvs' cons'' tmp_thy; |
36118
413d6d1f0f6e
share more code between definitional and axiomatic domain packages
huffman
parents:
36117
diff
changeset
|
172 |
val dts : typ list = map (Type o fst) eqs'; |
33798
46cbbcbd4e68
clean up indentation; add 'definitional' option flag
huffman
parents:
33796
diff
changeset
|
173 |
|
46cbbcbd4e68
clean up indentation; add 'definitional' option flag
huffman
parents:
33796
diff
changeset
|
174 |
fun mk_arg_typ (lazy, dest_opt, T) = if lazy then mk_uT T else T; |
46cbbcbd4e68
clean up indentation; add 'definitional' option flag
huffman
parents:
33796
diff
changeset
|
175 |
fun mk_con_typ (bind, args, mx) = |
46cbbcbd4e68
clean up indentation; add 'definitional' option flag
huffman
parents:
33796
diff
changeset
|
176 |
if null args then oneT else foldr1 mk_sprodT (map mk_arg_typ args); |
46cbbcbd4e68
clean up indentation; add 'definitional' option flag
huffman
parents:
33796
diff
changeset
|
177 |
fun mk_eq_typ (_, cons) = foldr1 mk_ssumT (map mk_con_typ cons); |
36118
413d6d1f0f6e
share more code between definitional and axiomatic domain packages
huffman
parents:
36117
diff
changeset
|
178 |
val repTs : typ list = map mk_eq_typ eqs'; |
33798
46cbbcbd4e68
clean up indentation; add 'definitional' option flag
huffman
parents:
33796
diff
changeset
|
179 |
|
36118
413d6d1f0f6e
share more code between definitional and axiomatic domain packages
huffman
parents:
36117
diff
changeset
|
180 |
val iso_spec : (binding * mixfix * (typ * typ)) list = |
413d6d1f0f6e
share more code between definitional and axiomatic domain packages
huffman
parents:
36117
diff
changeset
|
181 |
map (fn ((dbind, _, mx), eq) => (dbind, mx, eq)) |
413d6d1f0f6e
share more code between definitional and axiomatic domain packages
huffman
parents:
36117
diff
changeset
|
182 |
(dtnvs ~~ (dts ~~ repTs)); |
413d6d1f0f6e
share more code between definitional and axiomatic domain packages
huffman
parents:
36117
diff
changeset
|
183 |
|
413d6d1f0f6e
share more code between definitional and axiomatic domain packages
huffman
parents:
36117
diff
changeset
|
184 |
val ((iso_infos, take_info), thy) = add_isos iso_spec thy; |
413d6d1f0f6e
share more code between definitional and axiomatic domain packages
huffman
parents:
36117
diff
changeset
|
185 |
|
35520 | 186 |
val new_dts : (string * string list) list = |
187 |
map (fn ((s,Ts),_) => (s, map (fst o dest_TFree) Ts)) eqs'; |
|
188 |
fun one_con (con,args,mx) : cons = |
|
36118
413d6d1f0f6e
share more code between definitional and axiomatic domain packages
huffman
parents:
36117
diff
changeset
|
189 |
(Binding.name_of con, (* FIXME preverse binding (!?) *) |
33798
46cbbcbd4e68
clean up indentation; add 'definitional' option flag
huffman
parents:
33796
diff
changeset
|
190 |
ListPair.map (fn ((lazy,sel,tp),vn) => |
35519 | 191 |
mk_arg ((lazy, Datatype_Aux.dtyp_of_typ new_dts tp), vn)) |
36118
413d6d1f0f6e
share more code between definitional and axiomatic domain packages
huffman
parents:
36117
diff
changeset
|
192 |
(args, Datatype_Prop.make_tnames (map third args))); |
33798
46cbbcbd4e68
clean up indentation; add 'definitional' option flag
huffman
parents:
33796
diff
changeset
|
193 |
val eqs : eq list = |
46cbbcbd4e68
clean up indentation; add 'definitional' option flag
huffman
parents:
33796
diff
changeset
|
194 |
map (fn (dtnvs,cons') => (dtnvs, map one_con cons')) eqs'; |
36118
413d6d1f0f6e
share more code between definitional and axiomatic domain packages
huffman
parents:
36117
diff
changeset
|
195 |
|
33796 | 196 |
val ((rewss, take_rews), theorems_thy) = |
197 |
thy |
|
36118
413d6d1f0f6e
share more code between definitional and axiomatic domain packages
huffman
parents:
36117
diff
changeset
|
198 |
|> fold_map (fn (((dbind, eq), (_,cs)), info) => |
413d6d1f0f6e
share more code between definitional and axiomatic domain packages
huffman
parents:
36117
diff
changeset
|
199 |
Domain_Theorems.theorems (eq, eqs) dbind cs info take_info) |
35776
b0bc15d8ad3b
pass domain binding as argument to Domain_Theorems.theorems; proper qualified bindings for theorem names
huffman
parents:
35775
diff
changeset
|
200 |
(dbinds ~~ eqs ~~ eqs' ~~ iso_infos) |
35774 | 201 |
||>> Domain_Theorems.comp_theorems (comp_dbind, eqs) take_info; |
33796 | 202 |
in |
203 |
theorems_thy |
|
204 |
|> PureThy.add_thmss |
|
35774 | 205 |
[((Binding.qualified true "rews" comp_dbind, |
206 |
flat rewss @ take_rews), [])] |
|
33796 | 207 |
|> snd |
208 |
end; |
|
23152 | 209 |
|
36118
413d6d1f0f6e
share more code between definitional and axiomatic domain packages
huffman
parents:
36117
diff
changeset
|
210 |
fun define_isos (spec : (binding * mixfix * (typ * typ)) list) = |
413d6d1f0f6e
share more code between definitional and axiomatic domain packages
huffman
parents:
36117
diff
changeset
|
211 |
let |
413d6d1f0f6e
share more code between definitional and axiomatic domain packages
huffman
parents:
36117
diff
changeset
|
212 |
fun prep (dbind, mx, (lhsT, rhsT)) = |
413d6d1f0f6e
share more code between definitional and axiomatic domain packages
huffman
parents:
36117
diff
changeset
|
213 |
let val (dname, vs) = dest_Type lhsT; |
413d6d1f0f6e
share more code between definitional and axiomatic domain packages
huffman
parents:
36117
diff
changeset
|
214 |
in (map (fst o dest_TFree) vs, dbind, mx, rhsT, NONE) end; |
413d6d1f0f6e
share more code between definitional and axiomatic domain packages
huffman
parents:
36117
diff
changeset
|
215 |
in |
413d6d1f0f6e
share more code between definitional and axiomatic domain packages
huffman
parents:
36117
diff
changeset
|
216 |
Domain_Isomorphism.domain_isomorphism (map prep spec) |
413d6d1f0f6e
share more code between definitional and axiomatic domain packages
huffman
parents:
36117
diff
changeset
|
217 |
end; |
23152 | 218 |
|
36118
413d6d1f0f6e
share more code between definitional and axiomatic domain packages
huffman
parents:
36117
diff
changeset
|
219 |
val add_domain = |
413d6d1f0f6e
share more code between definitional and axiomatic domain packages
huffman
parents:
36117
diff
changeset
|
220 |
gen_add_domain Sign.certify_typ Domain_Axioms.add_axioms; |
413d6d1f0f6e
share more code between definitional and axiomatic domain packages
huffman
parents:
36117
diff
changeset
|
221 |
|
413d6d1f0f6e
share more code between definitional and axiomatic domain packages
huffman
parents:
36117
diff
changeset
|
222 |
val add_new_domain = |
413d6d1f0f6e
share more code between definitional and axiomatic domain packages
huffman
parents:
36117
diff
changeset
|
223 |
gen_add_domain Sign.certify_typ define_isos; |
413d6d1f0f6e
share more code between definitional and axiomatic domain packages
huffman
parents:
36117
diff
changeset
|
224 |
|
413d6d1f0f6e
share more code between definitional and axiomatic domain packages
huffman
parents:
36117
diff
changeset
|
225 |
val add_domain_cmd = |
413d6d1f0f6e
share more code between definitional and axiomatic domain packages
huffman
parents:
36117
diff
changeset
|
226 |
gen_add_domain Syntax.read_typ_global Domain_Axioms.add_axioms; |
413d6d1f0f6e
share more code between definitional and axiomatic domain packages
huffman
parents:
36117
diff
changeset
|
227 |
|
413d6d1f0f6e
share more code between definitional and axiomatic domain packages
huffman
parents:
36117
diff
changeset
|
228 |
val add_new_domain_cmd = |
413d6d1f0f6e
share more code between definitional and axiomatic domain packages
huffman
parents:
36117
diff
changeset
|
229 |
gen_add_domain Syntax.read_typ_global define_isos; |
33798
46cbbcbd4e68
clean up indentation; add 'definitional' option flag
huffman
parents:
33796
diff
changeset
|
230 |
|
23152 | 231 |
|
232 |
(** outer syntax **) |
|
233 |
||
234 |
local structure P = OuterParse and K = OuterKeyword in |
|
235 |
||
27353
71c4dd53d4cb
moved global keywords from OuterSyntax to OuterKeyword, tuned interfaces;
wenzelm
parents:
24926
diff
changeset
|
236 |
val _ = OuterKeyword.keyword "lazy"; |
24867 | 237 |
|
30919
dcf8a7a66bd1
make domain package ML interface more consistent with datatype package; use binding instead of bstring
huffman
parents:
30916
diff
changeset
|
238 |
val dest_decl : (bool * binding option * string) parser = |
33796 | 239 |
P.$$$ "(" |-- Scan.optional (P.$$$ "lazy" >> K true) false -- |
240 |
(P.binding >> SOME) -- (P.$$$ "::" |-- P.typ) --| P.$$$ ")" >> P.triple1 |
|
241 |
|| P.$$$ "(" |-- P.$$$ "lazy" |-- P.typ --| P.$$$ ")" |
|
242 |
>> (fn t => (true,NONE,t)) |
|
243 |
|| P.typ >> (fn t => (false,NONE,t)); |
|
23152 | 244 |
|
245 |
val cons_decl = |
|
33796 | 246 |
P.binding -- Scan.repeat dest_decl -- P.opt_mixfix; |
30916
a3d2128cac92
allow infix declarations for type constructors defined with domain package
huffman
parents:
30915
diff
changeset
|
247 |
|
a3d2128cac92
allow infix declarations for type constructors defined with domain package
huffman
parents:
30915
diff
changeset
|
248 |
val domain_decl = |
35839 | 249 |
(P.type_args_constrained -- P.binding -- P.opt_mixfix) -- |
33796 | 250 |
(P.$$$ "=" |-- P.enum1 "|" cons_decl); |
23152 | 251 |
|
30916
a3d2128cac92
allow infix declarations for type constructors defined with domain package
huffman
parents:
30915
diff
changeset
|
252 |
val domains_decl = |
35774 | 253 |
Scan.option (P.$$$ "(" |-- P.binding --| P.$$$ ")") -- |
33796 | 254 |
P.and_list1 domain_decl; |
23152 | 255 |
|
33796 | 256 |
fun mk_domain |
33798
46cbbcbd4e68
clean up indentation; add 'definitional' option flag
huffman
parents:
33796
diff
changeset
|
257 |
(definitional : bool) |
35774 | 258 |
(opt_name : binding option, |
33796 | 259 |
doms : ((((string * string option) list * binding) * mixfix) * |
260 |
((binding * (bool * binding option * string) list) * mixfix) list) list ) = |
|
261 |
let |
|
262 |
val names = map (fn (((_, t), _), _) => Binding.name_of t) doms; |
|
263 |
val specs : ((string * string option) list * binding * mixfix * |
|
264 |
(binding * (bool * binding option * string) list * mixfix) list) list = |
|
265 |
map (fn (((vs, t), mx), cons) => |
|
266 |
(vs, t, mx, map (fn ((c, ds), mx) => (c, ds, mx)) cons)) doms; |
|
35774 | 267 |
val comp_dbind = |
268 |
case opt_name of NONE => Binding.name (space_implode "_" names) |
|
269 |
| SOME s => s; |
|
33798
46cbbcbd4e68
clean up indentation; add 'definitional' option flag
huffman
parents:
33796
diff
changeset
|
270 |
in |
46cbbcbd4e68
clean up indentation; add 'definitional' option flag
huffman
parents:
33796
diff
changeset
|
271 |
if definitional |
35774 | 272 |
then add_new_domain_cmd comp_dbind specs |
273 |
else add_domain_cmd comp_dbind specs |
|
33798
46cbbcbd4e68
clean up indentation; add 'definitional' option flag
huffman
parents:
33796
diff
changeset
|
274 |
end; |
23152 | 275 |
|
24867 | 276 |
val _ = |
33796 | 277 |
OuterSyntax.command "domain" "define recursive domains (HOLCF)" |
33798
46cbbcbd4e68
clean up indentation; add 'definitional' option flag
huffman
parents:
33796
diff
changeset
|
278 |
K.thy_decl (domains_decl >> (Toplevel.theory o mk_domain false)); |
46cbbcbd4e68
clean up indentation; add 'definitional' option flag
huffman
parents:
33796
diff
changeset
|
279 |
|
46cbbcbd4e68
clean up indentation; add 'definitional' option flag
huffman
parents:
33796
diff
changeset
|
280 |
val _ = |
46cbbcbd4e68
clean up indentation; add 'definitional' option flag
huffman
parents:
33796
diff
changeset
|
281 |
OuterSyntax.command "new_domain" "define recursive domains (HOLCF)" |
46cbbcbd4e68
clean up indentation; add 'definitional' option flag
huffman
parents:
33796
diff
changeset
|
282 |
K.thy_decl (domains_decl >> (Toplevel.theory o mk_domain true)); |
23152 | 283 |
|
24867 | 284 |
end; |
23152 | 285 |
|
286 |
end; |