| author | wenzelm | 
| Thu, 05 Jun 2014 10:54:00 +0200 | |
| changeset 57311 | 550b704d665e | 
| parent 56941 | 952833323c99 | 
| child 59936 | b8ffc3dc9e24 | 
| permissions | -rw-r--r-- | 
| 42151 | 1  | 
(* Title: HOL/HOLCF/Tools/Domain/domain.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  | 
||
| 
40040
 
3adb92ee2f22
rename domain_theorems.ML to domain_induction.ML; rename domain_extender.ML to domain.ML
 
huffman 
parents: 
40026 
diff
changeset
 | 
8  | 
signature DOMAIN =  | 
| 23152 | 9  | 
sig  | 
| 33796 | 10  | 
val add_domain_cmd:  | 
11  | 
((string * string option) list * binding * mixfix *  | 
|
12  | 
(binding * (bool * binding option * string) list * mixfix) list) list  | 
|
13  | 
-> theory -> theory  | 
|
14  | 
||
15  | 
val add_domain:  | 
|
| 
40215
 
d8fd7ae0254f
change types of ML commands add_domain, add_new_domain to take 'sort' instead of 'string option'
 
huffman 
parents: 
40097 
diff
changeset
 | 
16  | 
((string * sort) list * binding * mixfix *  | 
| 33796 | 17  | 
(binding * (bool * binding option * typ) list * mixfix) list) list  | 
18  | 
-> theory -> theory  | 
|
| 
33798
 
46cbbcbd4e68
clean up indentation; add 'definitional' option flag
 
huffman 
parents: 
33796 
diff
changeset
 | 
19  | 
|
| 
 
46cbbcbd4e68
clean up indentation; add 'definitional' option flag
 
huffman 
parents: 
33796 
diff
changeset
 | 
20  | 
val add_new_domain_cmd:  | 
| 
 
46cbbcbd4e68
clean up indentation; add 'definitional' option flag
 
huffman 
parents: 
33796 
diff
changeset
 | 
21  | 
((string * string option) list * binding * mixfix *  | 
| 
 
46cbbcbd4e68
clean up indentation; add 'definitional' option flag
 
huffman 
parents: 
33796 
diff
changeset
 | 
22  | 
(binding * (bool * binding option * string) list * mixfix) list) list  | 
| 
 
46cbbcbd4e68
clean up indentation; add 'definitional' option flag
 
huffman 
parents: 
33796 
diff
changeset
 | 
23  | 
-> theory -> theory  | 
| 
 
46cbbcbd4e68
clean up indentation; add 'definitional' option flag
 
huffman 
parents: 
33796 
diff
changeset
 | 
24  | 
|
| 
 
46cbbcbd4e68
clean up indentation; add 'definitional' option flag
 
huffman 
parents: 
33796 
diff
changeset
 | 
25  | 
val add_new_domain:  | 
| 
40215
 
d8fd7ae0254f
change types of ML commands add_domain, add_new_domain to take 'sort' instead of 'string option'
 
huffman 
parents: 
40097 
diff
changeset
 | 
26  | 
((string * sort) list * binding * mixfix *  | 
| 
33798
 
46cbbcbd4e68
clean up indentation; add 'definitional' option flag
 
huffman 
parents: 
33796 
diff
changeset
 | 
27  | 
(binding * (bool * binding option * typ) list * mixfix) list) list  | 
| 
 
46cbbcbd4e68
clean up indentation; add 'definitional' option flag
 
huffman 
parents: 
33796 
diff
changeset
 | 
28  | 
-> theory -> theory  | 
| 40832 | 29  | 
end  | 
| 23152 | 30  | 
|
| 
41296
 
6aaf80ea9715
switch to transparent ascription, to avoid warning messages
 
huffman 
parents: 
40832 
diff
changeset
 | 
31  | 
structure Domain : DOMAIN =  | 
| 23152 | 32  | 
struct  | 
33  | 
||
| 40832 | 34  | 
open HOLCF_Library  | 
| 
40026
 
8f8f18a88685
remove last few dependencies on domain_library.ML and delete it; temporarily disable emptiness check
 
huffman 
parents: 
40019 
diff
changeset
 | 
35  | 
|
| 40832 | 36  | 
fun first (x,_,_) = x  | 
37  | 
fun second (_,x,_) = x  | 
|
| 
40026
 
8f8f18a88685
remove last few dependencies on domain_library.ML and delete it; temporarily disable emptiness check
 
huffman 
parents: 
40019 
diff
changeset
 | 
38  | 
|
| 23152 | 39  | 
(* ----- calls for building new thy and thms -------------------------------- *)  | 
40  | 
||
| 
36118
 
413d6d1f0f6e
share more code between definitional and axiomatic domain packages
 
huffman 
parents: 
36117 
diff
changeset
 | 
41  | 
type info =  | 
| 40832 | 42  | 
Domain_Take_Proofs.iso_info list * Domain_Take_Proofs.take_induct_info  | 
| 
36118
 
413d6d1f0f6e
share more code between definitional and axiomatic domain packages
 
huffman 
parents: 
36117 
diff
changeset
 | 
43  | 
|
| 40485 | 44  | 
fun add_arity ((b, sorts, mx), sort) thy : theory =  | 
45  | 
thy  | 
|
| 
42375
 
774df7c59508
report Name_Space.declare/define, relatively to context;
 
wenzelm 
parents: 
42361 
diff
changeset
 | 
46  | 
|> Sign.add_types_global [(b, length sorts, mx)]  | 
| 
56941
 
952833323c99
tuned signature to make axiomatizations more easy to spot in the source, via "add_axioms" or "axiomatization";
 
wenzelm 
parents: 
52788 
diff
changeset
 | 
47  | 
|> Axclass.arity_axiomatization (Sign.full_name thy b, sorts, sort)  | 
| 40485 | 48  | 
|
| 
30919
 
dcf8a7a66bd1
make domain package ML interface more consistent with datatype package; use binding instead of bstring
 
huffman 
parents: 
30916 
diff
changeset
 | 
49  | 
fun gen_add_domain  | 
| 
40215
 
d8fd7ae0254f
change types of ML commands add_domain, add_new_domain to take 'sort' instead of 'string option'
 
huffman 
parents: 
40097 
diff
changeset
 | 
50  | 
(prep_sort : theory -> 'a -> sort)  | 
| 
 
d8fd7ae0254f
change types of ML commands add_domain, add_new_domain to take 'sort' instead of 'string option'
 
huffman 
parents: 
40097 
diff
changeset
 | 
51  | 
(prep_typ : theory -> (string * sort) list -> 'b -> typ)  | 
| 
36118
 
413d6d1f0f6e
share more code between definitional and axiomatic domain packages
 
huffman 
parents: 
36117 
diff
changeset
 | 
52  | 
(add_isos : (binding * mixfix * (typ * typ)) list -> theory -> info * theory)  | 
| 
39965
 
da88519e6a0b
new_domain emits proper error message when a constructor argument type does not have sort 'rep'
 
huffman 
parents: 
39557 
diff
changeset
 | 
53  | 
(arg_sort : bool -> sort)  | 
| 
40215
 
d8fd7ae0254f
change types of ML commands add_domain, add_new_domain to take 'sort' instead of 'string option'
 
huffman 
parents: 
40097 
diff
changeset
 | 
54  | 
(raw_specs : ((string * 'a) list * binding * mixfix *  | 
| 
 
d8fd7ae0254f
change types of ML commands add_domain, add_new_domain to take 'sort' instead of 'string option'
 
huffman 
parents: 
40097 
diff
changeset
 | 
55  | 
(binding * (bool * binding option * 'b) list * mixfix) list) list)  | 
| 35516 | 56  | 
(thy : theory) =  | 
| 
33798
 
46cbbcbd4e68
clean up indentation; add 'definitional' option flag
 
huffman 
parents: 
33796 
diff
changeset
 | 
57  | 
let  | 
| 35520 | 58  | 
val dtnvs : (binding * typ list * mixfix) list =  | 
59  | 
let  | 
|
| 40832 | 60  | 
fun prep_tvar (a, s) = TFree (a, prep_sort thy s)  | 
| 35520 | 61  | 
in  | 
| 
40044
 
89381a2f8864
combine check_and_sort_domain with main function; rewrite much of the error-checking code
 
huffman 
parents: 
40043 
diff
changeset
 | 
62  | 
map (fn (vs, dbind, mx, _) =>  | 
| 
40215
 
d8fd7ae0254f
change types of ML commands add_domain, add_new_domain to take 'sort' instead of 'string option'
 
huffman 
parents: 
40097 
diff
changeset
 | 
63  | 
(dbind, map prep_tvar vs, mx)) raw_specs  | 
| 40832 | 64  | 
end  | 
| 
33798
 
46cbbcbd4e68
clean up indentation; add 'definitional' option flag
 
huffman 
parents: 
33796 
diff
changeset
 | 
65  | 
|
| 
40042
 
87c72a02eaf2
simplify check_and_sort_domain; more meaningful variable names
 
huffman 
parents: 
40040 
diff
changeset
 | 
66  | 
fun thy_arity (dbind, tvars, mx) =  | 
| 40832 | 67  | 
((dbind, map (snd o dest_TFree) tvars, mx), arg_sort false)  | 
| 
33798
 
46cbbcbd4e68
clean up indentation; add 'definitional' option flag
 
huffman 
parents: 
33796 
diff
changeset
 | 
68  | 
|
| 
 
46cbbcbd4e68
clean up indentation; add 'definitional' option flag
 
huffman 
parents: 
33796 
diff
changeset
 | 
69  | 
(* this theory is used just for parsing and error checking *)  | 
| 35516 | 70  | 
val tmp_thy = thy  | 
| 40832 | 71  | 
|> fold (add_arity o thy_arity) dtnvs  | 
| 
33798
 
46cbbcbd4e68
clean up indentation; add 'definitional' option flag
 
huffman 
parents: 
33796 
diff
changeset
 | 
72  | 
|
| 
35776
 
b0bc15d8ad3b
pass domain binding as argument to Domain_Theorems.theorems; proper qualified bindings for theorem names
 
huffman 
parents: 
35775 
diff
changeset
 | 
73  | 
val dbinds : binding list =  | 
| 40832 | 74  | 
map (fn (_,dbind,_,_) => dbind) raw_specs  | 
| 
40044
 
89381a2f8864
combine check_and_sort_domain with main function; rewrite much of the error-checking code
 
huffman 
parents: 
40043 
diff
changeset
 | 
75  | 
val raw_rhss :  | 
| 
40215
 
d8fd7ae0254f
change types of ML commands add_domain, add_new_domain to take 'sort' instead of 'string option'
 
huffman 
parents: 
40097 
diff
changeset
 | 
76  | 
(binding * (bool * binding option * 'b) list * mixfix) list list =  | 
| 40832 | 77  | 
map (fn (_,_,_,cons) => cons) raw_specs  | 
| 
33798
 
46cbbcbd4e68
clean up indentation; add 'definitional' option flag
 
huffman 
parents: 
33796 
diff
changeset
 | 
78  | 
val dtnvs' : (string * typ list) list =  | 
| 
44080
 
53d95b52954c
HOLCF: fix warnings about unreferenced identifiers
 
huffman 
parents: 
44005 
diff
changeset
 | 
79  | 
map (fn (dbind, vs, _) => (Sign.full_name thy dbind, vs)) dtnvs  | 
| 
40044
 
89381a2f8864
combine check_and_sort_domain with main function; rewrite much of the error-checking code
 
huffman 
parents: 
40043 
diff
changeset
 | 
80  | 
|
| 40832 | 81  | 
val all_cons = map (Binding.name_of o first) (flat raw_rhss)  | 
| 
44080
 
53d95b52954c
HOLCF: fix warnings about unreferenced identifiers
 
huffman 
parents: 
44005 
diff
changeset
 | 
82  | 
val _ =  | 
| 
40044
 
89381a2f8864
combine check_and_sort_domain with main function; rewrite much of the error-checking code
 
huffman 
parents: 
40043 
diff
changeset
 | 
83  | 
case duplicates (op =) all_cons of  | 
| 
 
89381a2f8864
combine check_and_sort_domain with main function; rewrite much of the error-checking code
 
huffman 
parents: 
40043 
diff
changeset
 | 
84  | 
        [] => false | dups => error ("Duplicate constructors: " 
 | 
| 40832 | 85  | 
^ commas_quote dups)  | 
| 
40044
 
89381a2f8864
combine check_and_sort_domain with main function; rewrite much of the error-checking code
 
huffman 
parents: 
40043 
diff
changeset
 | 
86  | 
val all_sels =  | 
| 40832 | 87  | 
(map Binding.name_of o map_filter second o maps second) (flat raw_rhss)  | 
| 
44080
 
53d95b52954c
HOLCF: fix warnings about unreferenced identifiers
 
huffman 
parents: 
44005 
diff
changeset
 | 
88  | 
val _ =  | 
| 
40044
 
89381a2f8864
combine check_and_sort_domain with main function; rewrite much of the error-checking code
 
huffman 
parents: 
40043 
diff
changeset
 | 
89  | 
case duplicates (op =) all_sels of  | 
| 40832 | 90  | 
        [] => false | dups => error("Duplicate selectors: "^commas_quote dups)
 | 
| 
40044
 
89381a2f8864
combine check_and_sort_domain with main function; rewrite much of the error-checking code
 
huffman 
parents: 
40043 
diff
changeset
 | 
91  | 
|
| 
 
89381a2f8864
combine check_and_sort_domain with main function; rewrite much of the error-checking code
 
huffman 
parents: 
40043 
diff
changeset
 | 
92  | 
fun test_dupl_tvars s =  | 
| 
 
89381a2f8864
combine check_and_sort_domain with main function; rewrite much of the error-checking code
 
huffman 
parents: 
40043 
diff
changeset
 | 
93  | 
case duplicates (op =) (map(fst o dest_TFree)s) of  | 
| 
 
89381a2f8864
combine check_and_sort_domain with main function; rewrite much of the error-checking code
 
huffman 
parents: 
40043 
diff
changeset
 | 
94  | 
        [] => false | dups => error("Duplicate type arguments: " 
 | 
| 40832 | 95  | 
^commas_quote dups)  | 
| 
44080
 
53d95b52954c
HOLCF: fix warnings about unreferenced identifiers
 
huffman 
parents: 
44005 
diff
changeset
 | 
96  | 
val _ = exists test_dupl_tvars (map snd dtnvs')  | 
| 
40044
 
89381a2f8864
combine check_and_sort_domain with main function; rewrite much of the error-checking code
 
huffman 
parents: 
40043 
diff
changeset
 | 
97  | 
|
| 
 
89381a2f8864
combine check_and_sort_domain with main function; rewrite much of the error-checking code
 
huffman 
parents: 
40043 
diff
changeset
 | 
98  | 
val sorts : (string * sort) list =  | 
| 40832 | 99  | 
let val all_sorts = map (map dest_TFree o snd) dtnvs'  | 
| 
40044
 
89381a2f8864
combine check_and_sort_domain with main function; rewrite much of the error-checking code
 
huffman 
parents: 
40043 
diff
changeset
 | 
100  | 
in  | 
| 
 
89381a2f8864
combine check_and_sort_domain with main function; rewrite much of the error-checking code
 
huffman 
parents: 
40043 
diff
changeset
 | 
101  | 
case distinct (eq_set (op =)) all_sorts of  | 
| 
 
89381a2f8864
combine check_and_sort_domain with main function; rewrite much of the error-checking code
 
huffman 
parents: 
40043 
diff
changeset
 | 
102  | 
[sorts] => sorts  | 
| 
 
89381a2f8864
combine check_and_sort_domain with main function; rewrite much of the error-checking code
 
huffman 
parents: 
40043 
diff
changeset
 | 
103  | 
| _ => error "Mutually recursive domains must have same type parameters"  | 
| 40832 | 104  | 
end  | 
| 
40044
 
89381a2f8864
combine check_and_sort_domain with main function; rewrite much of the error-checking code
 
huffman 
parents: 
40043 
diff
changeset
 | 
105  | 
|
| 
 
89381a2f8864
combine check_and_sort_domain with main function; rewrite much of the error-checking code
 
huffman 
parents: 
40043 
diff
changeset
 | 
106  | 
(* a lazy argument may have an unpointed type *)  | 
| 
 
89381a2f8864
combine check_and_sort_domain with main function; rewrite much of the error-checking code
 
huffman 
parents: 
40043 
diff
changeset
 | 
107  | 
(* unless the argument has a selector function *)  | 
| 
 
89381a2f8864
combine check_and_sort_domain with main function; rewrite much of the error-checking code
 
huffman 
parents: 
40043 
diff
changeset
 | 
108  | 
fun check_pcpo (lazy, sel, T) =  | 
| 
 
89381a2f8864
combine check_and_sort_domain with main function; rewrite much of the error-checking code
 
huffman 
parents: 
40043 
diff
changeset
 | 
109  | 
let val sort = arg_sort (lazy andalso is_none sel) in  | 
| 
 
89381a2f8864
combine check_and_sort_domain with main function; rewrite much of the error-checking code
 
huffman 
parents: 
40043 
diff
changeset
 | 
110  | 
if Sign.of_sort tmp_thy (T, sort) then ()  | 
| 
 
89381a2f8864
combine check_and_sort_domain with main function; rewrite much of the error-checking code
 
huffman 
parents: 
40043 
diff
changeset
 | 
111  | 
        else error ("Constructor argument type is not of sort " ^
 | 
| 
 
89381a2f8864
combine check_and_sort_domain with main function; rewrite much of the error-checking code
 
huffman 
parents: 
40043 
diff
changeset
 | 
112  | 
Syntax.string_of_sort_global tmp_thy sort ^ ": " ^  | 
| 
 
89381a2f8864
combine check_and_sort_domain with main function; rewrite much of the error-checking code
 
huffman 
parents: 
40043 
diff
changeset
 | 
113  | 
Syntax.string_of_typ_global tmp_thy T)  | 
| 40832 | 114  | 
end  | 
| 
40044
 
89381a2f8864
combine check_and_sort_domain with main function; rewrite much of the error-checking code
 
huffman 
parents: 
40043 
diff
changeset
 | 
115  | 
|
| 
 
89381a2f8864
combine check_and_sort_domain with main function; rewrite much of the error-checking code
 
huffman 
parents: 
40043 
diff
changeset
 | 
116  | 
(* test for free type variables, illegal sort constraints on rhs,  | 
| 40832 | 117  | 
non-pcpo-types and invalid use of recursive type  | 
| 
40044
 
89381a2f8864
combine check_and_sort_domain with main function; rewrite much of the error-checking code
 
huffman 
parents: 
40043 
diff
changeset
 | 
118  | 
replace sorts in type variables on rhs *)  | 
| 40832 | 119  | 
val rec_tab = Domain_Take_Proofs.get_rec_tab thy  | 
| 
44080
 
53d95b52954c
HOLCF: fix warnings about unreferenced identifiers
 
huffman 
parents: 
44005 
diff
changeset
 | 
120  | 
fun check_rec _ (T as TFree (v,_)) =  | 
| 
40044
 
89381a2f8864
combine check_and_sort_domain with main function; rewrite much of the error-checking code
 
huffman 
parents: 
40043 
diff
changeset
 | 
121  | 
if AList.defined (op =) sorts v then T  | 
| 
 
89381a2f8864
combine check_and_sort_domain with main function; rewrite much of the error-checking code
 
huffman 
parents: 
40043 
diff
changeset
 | 
122  | 
        else error ("Free type variable " ^ quote v ^ " on rhs.")
 | 
| 
44005
 
421f8bc19ce4
domain package: more informative error message for illegal indirect recursion
 
huffman 
parents: 
42375 
diff
changeset
 | 
123  | 
| check_rec no_rec (T as Type (s, Ts)) =  | 
| 
40044
 
89381a2f8864
combine check_and_sort_domain with main function; rewrite much of the error-checking code
 
huffman 
parents: 
40043 
diff
changeset
 | 
124  | 
(case AList.lookup (op =) dtnvs' s of  | 
| 
 
89381a2f8864
combine check_and_sort_domain with main function; rewrite much of the error-checking code
 
huffman 
parents: 
40043 
diff
changeset
 | 
125  | 
NONE =>  | 
| 
44005
 
421f8bc19ce4
domain package: more informative error message for illegal indirect recursion
 
huffman 
parents: 
42375 
diff
changeset
 | 
126  | 
let val no_rec' =  | 
| 
 
421f8bc19ce4
domain package: more informative error message for illegal indirect recursion
 
huffman 
parents: 
42375 
diff
changeset
 | 
127  | 
if no_rec = NONE then  | 
| 
 
421f8bc19ce4
domain package: more informative error message for illegal indirect recursion
 
huffman 
parents: 
42375 
diff
changeset
 | 
128  | 
if Symtab.defined rec_tab s then NONE else SOME s  | 
| 
 
421f8bc19ce4
domain package: more informative error message for illegal indirect recursion
 
huffman 
parents: 
42375 
diff
changeset
 | 
129  | 
else no_rec  | 
| 
 
421f8bc19ce4
domain package: more informative error message for illegal indirect recursion
 
huffman 
parents: 
42375 
diff
changeset
 | 
130  | 
in Type (s, map (check_rec no_rec') Ts) end  | 
| 
40044
 
89381a2f8864
combine check_and_sort_domain with main function; rewrite much of the error-checking code
 
huffman 
parents: 
40043 
diff
changeset
 | 
131  | 
| SOME typevars =>  | 
| 
 
89381a2f8864
combine check_and_sort_domain with main function; rewrite much of the error-checking code
 
huffman 
parents: 
40043 
diff
changeset
 | 
132  | 
if typevars <> Ts  | 
| 
 
89381a2f8864
combine check_and_sort_domain with main function; rewrite much of the error-checking code
 
huffman 
parents: 
40043 
diff
changeset
 | 
133  | 
          then error ("Recursion of type " ^ 
 | 
| 
 
89381a2f8864
combine check_and_sort_domain with main function; rewrite much of the error-checking code
 
huffman 
parents: 
40043 
diff
changeset
 | 
134  | 
quote (Syntax.string_of_typ_global tmp_thy T) ^  | 
| 
 
89381a2f8864
combine check_and_sort_domain with main function; rewrite much of the error-checking code
 
huffman 
parents: 
40043 
diff
changeset
 | 
135  | 
" with different arguments")  | 
| 
44005
 
421f8bc19ce4
domain package: more informative error message for illegal indirect recursion
 
huffman 
parents: 
42375 
diff
changeset
 | 
136  | 
else (case no_rec of  | 
| 
 
421f8bc19ce4
domain package: more informative error message for illegal indirect recursion
 
huffman 
parents: 
42375 
diff
changeset
 | 
137  | 
NONE => T  | 
| 
 
421f8bc19ce4
domain package: more informative error message for illegal indirect recursion
 
huffman 
parents: 
42375 
diff
changeset
 | 
138  | 
| SOME c =>  | 
| 
 
421f8bc19ce4
domain package: more informative error message for illegal indirect recursion
 
huffman 
parents: 
42375 
diff
changeset
 | 
139  | 
                  error ("Illegal indirect recursion of type " ^ 
 | 
| 
 
421f8bc19ce4
domain package: more informative error message for illegal indirect recursion
 
huffman 
parents: 
42375 
diff
changeset
 | 
140  | 
quote (Syntax.string_of_typ_global tmp_thy T) ^  | 
| 
 
421f8bc19ce4
domain package: more informative error message for illegal indirect recursion
 
huffman 
parents: 
42375 
diff
changeset
 | 
141  | 
" under type constructor " ^ quote c)))  | 
| 
44080
 
53d95b52954c
HOLCF: fix warnings about unreferenced identifiers
 
huffman 
parents: 
44005 
diff
changeset
 | 
142  | 
| check_rec _ (TVar _) = error "extender:check_rec"  | 
| 
40044
 
89381a2f8864
combine check_and_sort_domain with main function; rewrite much of the error-checking code
 
huffman 
parents: 
40043 
diff
changeset
 | 
143  | 
|
| 
 
89381a2f8864
combine check_and_sort_domain with main function; rewrite much of the error-checking code
 
huffman 
parents: 
40043 
diff
changeset
 | 
144  | 
fun prep_arg (lazy, sel, raw_T) =  | 
| 
 
89381a2f8864
combine check_and_sort_domain with main function; rewrite much of the error-checking code
 
huffman 
parents: 
40043 
diff
changeset
 | 
145  | 
let  | 
| 40832 | 146  | 
val T = prep_typ tmp_thy sorts raw_T  | 
| 
44005
 
421f8bc19ce4
domain package: more informative error message for illegal indirect recursion
 
huffman 
parents: 
42375 
diff
changeset
 | 
147  | 
val _ = check_rec NONE T  | 
| 40832 | 148  | 
val _ = check_pcpo (lazy, sel, T)  | 
149  | 
in (lazy, sel, T) end  | 
|
150  | 
fun prep_con (b, args, mx) = (b, map prep_arg args, mx)  | 
|
151  | 
fun prep_rhs cons = map prep_con cons  | 
|
| 
40044
 
89381a2f8864
combine check_and_sort_domain with main function; rewrite much of the error-checking code
 
huffman 
parents: 
40043 
diff
changeset
 | 
152  | 
val rhss : (binding * (bool * binding option * typ) list * mixfix) list list =  | 
| 40832 | 153  | 
map prep_rhs raw_rhss  | 
| 
33798
 
46cbbcbd4e68
clean up indentation; add 'definitional' option flag
 
huffman 
parents: 
33796 
diff
changeset
 | 
154  | 
|
| 
44080
 
53d95b52954c
HOLCF: fix warnings about unreferenced identifiers
 
huffman 
parents: 
44005 
diff
changeset
 | 
155  | 
fun mk_arg_typ (lazy, _, T) = if lazy then mk_upT T else T  | 
| 
 
53d95b52954c
HOLCF: fix warnings about unreferenced identifiers
 
huffman 
parents: 
44005 
diff
changeset
 | 
156  | 
fun mk_con_typ (_, args, _) =  | 
| 40832 | 157  | 
if null args then oneT else foldr1 mk_sprodT (map mk_arg_typ args)  | 
158  | 
fun mk_rhs_typ cons = foldr1 mk_ssumT (map mk_con_typ cons)  | 
|
| 
40042
 
87c72a02eaf2
simplify check_and_sort_domain; more meaningful variable names
 
huffman 
parents: 
40040 
diff
changeset
 | 
159  | 
|
| 40832 | 160  | 
val absTs : typ list = map Type dtnvs'  | 
161  | 
val repTs : typ list = map mk_rhs_typ rhss  | 
|
| 
33798
 
46cbbcbd4e68
clean up indentation; add 'definitional' option flag
 
huffman 
parents: 
33796 
diff
changeset
 | 
162  | 
|
| 
36118
 
413d6d1f0f6e
share more code between definitional and axiomatic domain packages
 
huffman 
parents: 
36117 
diff
changeset
 | 
163  | 
val iso_spec : (binding * mixfix * (typ * typ)) list =  | 
| 
 
413d6d1f0f6e
share more code between definitional and axiomatic domain packages
 
huffman 
parents: 
36117 
diff
changeset
 | 
164  | 
map (fn ((dbind, _, mx), eq) => (dbind, mx, eq))  | 
| 40832 | 165  | 
(dtnvs ~~ (absTs ~~ repTs))  | 
| 
36118
 
413d6d1f0f6e
share more code between definitional and axiomatic domain packages
 
huffman 
parents: 
36117 
diff
changeset
 | 
166  | 
|
| 40832 | 167  | 
val ((iso_infos, take_info), thy) = add_isos iso_spec thy  | 
| 
36118
 
413d6d1f0f6e
share more code between definitional and axiomatic domain packages
 
huffman 
parents: 
36117 
diff
changeset
 | 
168  | 
|
| 
40016
 
2eff1cbc1ccb
remove function Domain_Theorems.theorems; bind theorem names directly from Domain_Constructors.add_domain_constructors
 
huffman 
parents: 
39986 
diff
changeset
 | 
169  | 
val (constr_infos, thy) =  | 
| 33796 | 170  | 
thy  | 
| 
40042
 
87c72a02eaf2
simplify check_and_sort_domain; more meaningful variable names
 
huffman 
parents: 
40040 
diff
changeset
 | 
171  | 
|> fold_map (fn ((dbind, cons), info) =>  | 
| 
 
87c72a02eaf2
simplify check_and_sort_domain; more meaningful variable names
 
huffman 
parents: 
40040 
diff
changeset
 | 
172  | 
Domain_Constructors.add_domain_constructors dbind cons info)  | 
| 40832 | 173  | 
(dbinds ~~ rhss ~~ iso_infos)  | 
| 
40016
 
2eff1cbc1ccb
remove function Domain_Theorems.theorems; bind theorem names directly from Domain_Constructors.add_domain_constructors
 
huffman 
parents: 
39986 
diff
changeset
 | 
174  | 
|
| 
44080
 
53d95b52954c
HOLCF: fix warnings about unreferenced identifiers
 
huffman 
parents: 
44005 
diff
changeset
 | 
175  | 
val (_, thy) =  | 
| 
40097
 
429cd74f795f
remove legacy comp_dbind option from domain package
 
huffman 
parents: 
40044 
diff
changeset
 | 
176  | 
Domain_Induction.comp_theorems  | 
| 40832 | 177  | 
dbinds take_info constr_infos thy  | 
| 33796 | 178  | 
in  | 
| 
40026
 
8f8f18a88685
remove last few dependencies on domain_library.ML and delete it; temporarily disable emptiness check
 
huffman 
parents: 
40019 
diff
changeset
 | 
179  | 
thy  | 
| 40832 | 180  | 
end  | 
| 23152 | 181  | 
|
| 
36118
 
413d6d1f0f6e
share more code between definitional and axiomatic domain packages
 
huffman 
parents: 
36117 
diff
changeset
 | 
182  | 
fun define_isos (spec : (binding * mixfix * (typ * typ)) list) =  | 
| 
 
413d6d1f0f6e
share more code between definitional and axiomatic domain packages
 
huffman 
parents: 
36117 
diff
changeset
 | 
183  | 
let  | 
| 
 
413d6d1f0f6e
share more code between definitional and axiomatic domain packages
 
huffman 
parents: 
36117 
diff
changeset
 | 
184  | 
fun prep (dbind, mx, (lhsT, rhsT)) =  | 
| 
44080
 
53d95b52954c
HOLCF: fix warnings about unreferenced identifiers
 
huffman 
parents: 
44005 
diff
changeset
 | 
185  | 
let val (_, vs) = dest_Type lhsT  | 
| 40832 | 186  | 
in (map (fst o dest_TFree) vs, dbind, mx, rhsT, NONE) end  | 
| 
36118
 
413d6d1f0f6e
share more code between definitional and axiomatic domain packages
 
huffman 
parents: 
36117 
diff
changeset
 | 
187  | 
in  | 
| 
 
413d6d1f0f6e
share more code between definitional and axiomatic domain packages
 
huffman 
parents: 
36117 
diff
changeset
 | 
188  | 
Domain_Isomorphism.domain_isomorphism (map prep spec)  | 
| 40832 | 189  | 
end  | 
| 23152 | 190  | 
|
| 40832 | 191  | 
fun pcpo_arg lazy = if lazy then @{sort cpo} else @{sort pcpo}
 | 
192  | 
fun rep_arg lazy = if lazy then @{sort predomain} else @{sort "domain"}
 | 
|
| 
39965
 
da88519e6a0b
new_domain emits proper error message when a constructor argument type does not have sort 'rep'
 
huffman 
parents: 
39557 
diff
changeset
 | 
193  | 
|
| 
40215
 
d8fd7ae0254f
change types of ML commands add_domain, add_new_domain to take 'sort' instead of 'string option'
 
huffman 
parents: 
40097 
diff
changeset
 | 
194  | 
fun read_sort thy (SOME s) = Syntax.read_sort_global thy s  | 
| 40832 | 195  | 
| read_sort thy NONE = Sign.defaultS thy  | 
| 
40215
 
d8fd7ae0254f
change types of ML commands add_domain, add_new_domain to take 'sort' instead of 'string option'
 
huffman 
parents: 
40097 
diff
changeset
 | 
196  | 
|
| 
40044
 
89381a2f8864
combine check_and_sort_domain with main function; rewrite much of the error-checking code
 
huffman 
parents: 
40043 
diff
changeset
 | 
197  | 
(* Adapted from src/HOL/Tools/Datatype/datatype_data.ML *)  | 
| 
 
89381a2f8864
combine check_and_sort_domain with main function; rewrite much of the error-checking code
 
huffman 
parents: 
40043 
diff
changeset
 | 
198  | 
fun read_typ thy sorts str =  | 
| 
 
89381a2f8864
combine check_and_sort_domain with main function; rewrite much of the error-checking code
 
huffman 
parents: 
40043 
diff
changeset
 | 
199  | 
let  | 
| 42361 | 200  | 
val ctxt = Proof_Context.init_global thy  | 
| 40832 | 201  | 
|> fold (Variable.declare_typ o TFree) sorts  | 
202  | 
in Syntax.read_typ ctxt str end  | 
|
| 
40044
 
89381a2f8864
combine check_and_sort_domain with main function; rewrite much of the error-checking code
 
huffman 
parents: 
40043 
diff
changeset
 | 
203  | 
|
| 
 
89381a2f8864
combine check_and_sort_domain with main function; rewrite much of the error-checking code
 
huffman 
parents: 
40043 
diff
changeset
 | 
204  | 
fun cert_typ sign sorts raw_T =  | 
| 
 
89381a2f8864
combine check_and_sort_domain with main function; rewrite much of the error-checking code
 
huffman 
parents: 
40043 
diff
changeset
 | 
205  | 
let  | 
| 
 
89381a2f8864
combine check_and_sort_domain with main function; rewrite much of the error-checking code
 
huffman 
parents: 
40043 
diff
changeset
 | 
206  | 
val T = Type.no_tvars (Sign.certify_typ sign raw_T)  | 
| 40832 | 207  | 
handle TYPE (msg, _, _) => error msg  | 
208  | 
val sorts' = Term.add_tfreesT T sorts  | 
|
| 
40044
 
89381a2f8864
combine check_and_sort_domain with main function; rewrite much of the error-checking code
 
huffman 
parents: 
40043 
diff
changeset
 | 
209  | 
val _ =  | 
| 
 
89381a2f8864
combine check_and_sort_domain with main function; rewrite much of the error-checking code
 
huffman 
parents: 
40043 
diff
changeset
 | 
210  | 
case duplicates (op =) (map fst sorts') of  | 
| 
 
89381a2f8864
combine check_and_sort_domain with main function; rewrite much of the error-checking code
 
huffman 
parents: 
40043 
diff
changeset
 | 
211  | 
[] => ()  | 
| 
 
89381a2f8864
combine check_and_sort_domain with main function; rewrite much of the error-checking code
 
huffman 
parents: 
40043 
diff
changeset
 | 
212  | 
      | dups => error ("Inconsistent sort constraints for " ^ commas dups)
 | 
| 40832 | 213  | 
in T end  | 
| 
40044
 
89381a2f8864
combine check_and_sort_domain with main function; rewrite much of the error-checking code
 
huffman 
parents: 
40043 
diff
changeset
 | 
214  | 
|
| 
36118
 
413d6d1f0f6e
share more code between definitional and axiomatic domain packages
 
huffman 
parents: 
36117 
diff
changeset
 | 
215  | 
val add_domain =  | 
| 40832 | 216  | 
gen_add_domain (K I) cert_typ Domain_Axioms.add_axioms pcpo_arg  | 
| 
36118
 
413d6d1f0f6e
share more code between definitional and axiomatic domain packages
 
huffman 
parents: 
36117 
diff
changeset
 | 
217  | 
|
| 
 
413d6d1f0f6e
share more code between definitional and axiomatic domain packages
 
huffman 
parents: 
36117 
diff
changeset
 | 
218  | 
val add_new_domain =  | 
| 40832 | 219  | 
gen_add_domain (K I) cert_typ define_isos rep_arg  | 
| 
36118
 
413d6d1f0f6e
share more code between definitional and axiomatic domain packages
 
huffman 
parents: 
36117 
diff
changeset
 | 
220  | 
|
| 
 
413d6d1f0f6e
share more code between definitional and axiomatic domain packages
 
huffman 
parents: 
36117 
diff
changeset
 | 
221  | 
val add_domain_cmd =  | 
| 40832 | 222  | 
gen_add_domain read_sort read_typ Domain_Axioms.add_axioms pcpo_arg  | 
| 
36118
 
413d6d1f0f6e
share more code between definitional and axiomatic domain packages
 
huffman 
parents: 
36117 
diff
changeset
 | 
223  | 
|
| 
 
413d6d1f0f6e
share more code between definitional and axiomatic domain packages
 
huffman 
parents: 
36117 
diff
changeset
 | 
224  | 
val add_new_domain_cmd =  | 
| 40832 | 225  | 
gen_add_domain read_sort read_typ define_isos rep_arg  | 
| 
33798
 
46cbbcbd4e68
clean up indentation; add 'definitional' option flag
 
huffman 
parents: 
33796 
diff
changeset
 | 
226  | 
|
| 23152 | 227  | 
|
228  | 
(** outer syntax **)  | 
|
229  | 
||
| 
30919
 
dcf8a7a66bd1
make domain package ML interface more consistent with datatype package; use binding instead of bstring
 
huffman 
parents: 
30916 
diff
changeset
 | 
230  | 
val dest_decl : (bool * binding option * string) parser =  | 
| 46949 | 231  | 
  @{keyword "("} |-- Scan.optional (@{keyword "lazy"} >> K true) false --
 | 
232  | 
    (Parse.binding >> SOME) -- (@{keyword "::"} |-- Parse.typ)  --| @{keyword ")"} >> Parse.triple1
 | 
|
233  | 
    || @{keyword "("} |-- @{keyword "lazy"} |-- Parse.typ --| @{keyword ")"}
 | 
|
234  | 
>> (fn t => (true, NONE, t))  | 
|
235  | 
|| Parse.typ >> (fn t => (false, NONE, t))  | 
|
| 23152 | 236  | 
|
237  | 
val cons_decl =  | 
|
| 40832 | 238  | 
Parse.binding -- Scan.repeat dest_decl -- Parse.opt_mixfix  | 
| 
30916
 
a3d2128cac92
allow infix declarations for type constructors defined with domain package
 
huffman 
parents: 
30915 
diff
changeset
 | 
239  | 
|
| 
 
a3d2128cac92
allow infix declarations for type constructors defined with domain package
 
huffman 
parents: 
30915 
diff
changeset
 | 
240  | 
val domain_decl =  | 
| 
36960
 
01594f816e3a
prefer structure Keyword, Parse, Parse_Spec, Outer_Syntax;
 
wenzelm 
parents: 
36119 
diff
changeset
 | 
241  | 
(Parse.type_args_constrained -- Parse.binding -- Parse.opt_mixfix) --  | 
| 46949 | 242  | 
    (@{keyword "="} |-- Parse.enum1 "|" cons_decl)
 | 
| 23152 | 243  | 
|
| 
30916
 
a3d2128cac92
allow infix declarations for type constructors defined with domain package
 
huffman 
parents: 
30915 
diff
changeset
 | 
244  | 
val domains_decl =  | 
| 46949 | 245  | 
  Scan.optional (@{keyword "("} |-- (@{keyword "unsafe"} >> K true) --| @{keyword ")"}) false --
 | 
| 40832 | 246  | 
Parse.and_list1 domain_decl  | 
| 23152 | 247  | 
|
| 33796 | 248  | 
fun mk_domain  | 
| 
40329
 
73f2b99b549d
change default_sort of HOLCF from pcpo to bifinite; rename command 'new_domain' to 'domain'; rename 'domain' to 'domain (unsafe)'
 
huffman 
parents: 
40215 
diff
changeset
 | 
249  | 
(unsafe : bool,  | 
| 
 
73f2b99b549d
change default_sort of HOLCF from pcpo to bifinite; rename command 'new_domain' to 'domain'; rename 'domain' to 'domain (unsafe)'
 
huffman 
parents: 
40215 
diff
changeset
 | 
250  | 
doms : ((((string * string option) list * binding) * mixfix) *  | 
| 33796 | 251  | 
((binding * (bool * binding option * string) list) * mixfix) list) list ) =  | 
252  | 
let  | 
|
253  | 
val specs : ((string * string option) list * binding * mixfix *  | 
|
254  | 
(binding * (bool * binding option * string) list * mixfix) list) list =  | 
|
255  | 
map (fn (((vs, t), mx), cons) =>  | 
|
| 40832 | 256  | 
(vs, t, mx, map (fn ((c, ds), mx) => (c, ds, mx)) cons)) doms  | 
| 
33798
 
46cbbcbd4e68
clean up indentation; add 'definitional' option flag
 
huffman 
parents: 
33796 
diff
changeset
 | 
257  | 
in  | 
| 
40329
 
73f2b99b549d
change default_sort of HOLCF from pcpo to bifinite; rename command 'new_domain' to 'domain'; rename 'domain' to 'domain (unsafe)'
 
huffman 
parents: 
40215 
diff
changeset
 | 
258  | 
if unsafe  | 
| 
 
73f2b99b549d
change default_sort of HOLCF from pcpo to bifinite; rename command 'new_domain' to 'domain'; rename 'domain' to 'domain (unsafe)'
 
huffman 
parents: 
40215 
diff
changeset
 | 
259  | 
then add_domain_cmd specs  | 
| 
 
73f2b99b549d
change default_sort of HOLCF from pcpo to bifinite; rename command 'new_domain' to 'domain'; rename 'domain' to 'domain (unsafe)'
 
huffman 
parents: 
40215 
diff
changeset
 | 
260  | 
else add_new_domain_cmd specs  | 
| 40832 | 261  | 
end  | 
| 23152 | 262  | 
|
| 24867 | 263  | 
val _ =  | 
| 
46961
 
5c6955f487e5
outer syntax command definitions based on formal command_spec derived from theory header declarations;
 
wenzelm 
parents: 
46949 
diff
changeset
 | 
264  | 
  Outer_Syntax.command @{command_spec "domain"} "define recursive domains (HOLCF)"
 | 
| 
 
5c6955f487e5
outer syntax command definitions based on formal command_spec derived from theory header declarations;
 
wenzelm 
parents: 
46949 
diff
changeset
 | 
265  | 
(domains_decl >> (Toplevel.theory o mk_domain))  | 
| 23152 | 266  | 
|
| 40832 | 267  | 
end  |