97 val subst_TVars_Vartab: typ Vartab.table -> term -> term |
97 val subst_TVars_Vartab: typ Vartab.table -> term -> term |
98 val betapply: term * term -> term |
98 val betapply: term * term -> term |
99 val eq_ix: indexname * indexname -> bool |
99 val eq_ix: indexname * indexname -> bool |
100 val ins_ix: indexname * indexname list -> indexname list |
100 val ins_ix: indexname * indexname list -> indexname list |
101 val mem_ix: indexname * indexname list -> bool |
101 val mem_ix: indexname * indexname list -> bool |
102 val eq_sort: sort * class list -> bool |
|
103 val mem_sort: sort * class list list -> bool |
|
104 val subset_sort: sort list * class list list -> bool |
|
105 val eq_set_sort: sort list * sort list -> bool |
|
106 val ins_sort: sort * class list list -> class list list |
|
107 val union_sort: sort list * sort list -> sort list |
|
108 val rems_sort: sort list * sort list -> sort list |
|
109 val aconv: term * term -> bool |
102 val aconv: term * term -> bool |
110 val aconvs: term list * term list -> bool |
103 val aconvs: term list * term list -> bool |
111 val mem_term: term * term list -> bool |
104 val mem_term: term * term list -> bool |
112 val subset_term: term list * term list -> bool |
105 val subset_term: term list * term list -> bool |
113 val eq_set_term: term list * term list -> bool |
106 val eq_set_term: term list * term list -> bool |
190 val typs_ord: typ list * typ list -> order |
183 val typs_ord: typ list * typ list -> order |
191 val term_ord: term * term -> order |
184 val term_ord: term * term -> order |
192 val terms_ord: term list * term list -> order |
185 val terms_ord: term list * term list -> order |
193 val hd_ord: term * term -> order |
186 val hd_ord: term * term -> order |
194 val termless: term * term -> bool |
187 val termless: term * term -> bool |
|
188 val no_dummyT: typ -> typ |
195 val dummy_patternN: string |
189 val dummy_patternN: string |
196 val no_dummy_patterns: term -> term |
190 val no_dummy_patterns: term -> term |
197 val replace_dummy_patterns: int * term -> int * term |
191 val replace_dummy_patterns: int * term -> int * term |
198 val is_replaced_dummy_pattern: indexname -> bool |
192 val is_replaced_dummy_pattern: indexname -> bool |
199 val adhoc_freeze_vars: term -> term * string list |
193 val adhoc_freeze_vars: term -> term * string list |
|
194 val string_of_vname: indexname -> string |
|
195 val string_of_vname': indexname -> string |
200 end; |
196 end; |
201 |
197 |
202 structure Term: TERM = |
198 structure Term: TERM = |
203 struct |
199 struct |
204 |
200 |
531 |
527 |
532 (*beta-reduce if possible, else form application*) |
528 (*beta-reduce if possible, else form application*) |
533 fun betapply (Abs(_,_,t), u) = subst_bound (u,t) |
529 fun betapply (Abs(_,_,t), u) = subst_bound (u,t) |
534 | betapply (f,u) = f$u; |
530 | betapply (f,u) = f$u; |
535 |
531 |
|
532 |
536 (** Equality, membership and insertion of indexnames (string*ints) **) |
533 (** Equality, membership and insertion of indexnames (string*ints) **) |
537 |
534 |
538 (*optimized equality test for indexnames. Yields a huge gain under Poly/ML*) |
535 (*optimized equality test for indexnames. Yields a huge gain under Poly/ML*) |
539 fun eq_ix ((a, i):indexname, (a',i'):indexname) = (a=a') andalso i=i'; |
536 fun eq_ix ((a, i):indexname, (a',i'):indexname) = (a=a') andalso i=i'; |
540 |
537 |
573 | union_term ((x :: xs), ys) = union_term (xs, ins_term (x, ys)); |
570 | union_term ((x :: xs), ys) = union_term (xs, ins_term (x, ys)); |
574 |
571 |
575 fun inter_term ([], ys) = [] |
572 fun inter_term ([], ys) = [] |
576 | inter_term (x::xs, ys) = |
573 | inter_term (x::xs, ys) = |
577 if mem_term (x,ys) then x :: inter_term(xs,ys) else inter_term(xs,ys); |
574 if mem_term (x,ys) then x :: inter_term(xs,ys) else inter_term(xs,ys); |
578 |
|
579 (** Equality, membership and insertion of sorts (string lists) **) |
|
580 |
|
581 fun eq_sort ([]:sort, []) = true |
|
582 | eq_sort ((s::ss), (t::ts)) = s=t andalso eq_sort(ss,ts) |
|
583 | eq_sort (_, _) = false; |
|
584 |
|
585 fun mem_sort (_:sort, []) = false |
|
586 | mem_sort (S, S'::Ss) = eq_sort (S, S') orelse mem_sort(S,Ss); |
|
587 |
|
588 fun ins_sort(S,Ss) = if mem_sort(S,Ss) then Ss else S :: Ss; |
|
589 |
|
590 fun union_sort (xs, []) = xs |
|
591 | union_sort ([], ys) = ys |
|
592 | union_sort ((x :: xs), ys) = union_sort (xs, ins_sort (x, ys)); |
|
593 |
|
594 fun subset_sort ([], ys) = true |
|
595 | subset_sort (x :: xs, ys) = mem_sort (x, ys) andalso subset_sort(xs, ys); |
|
596 |
|
597 fun eq_set_sort (xs, ys) = |
|
598 xs = ys orelse (subset_sort (xs, ys) andalso subset_sort (ys, xs)); |
|
599 |
|
600 val rems_sort = gen_rems eq_sort; |
|
601 |
575 |
602 (*are two term lists alpha-convertible in corresponding elements?*) |
576 (*are two term lists alpha-convertible in corresponding elements?*) |
603 fun aconvs ([],[]) = true |
577 fun aconvs ([],[]) = true |
604 | aconvs (t::ts, u::us) = t aconv u andalso aconvs(ts,us) |
578 | aconvs (t::ts, u::us) = t aconv u andalso aconvs(ts,us) |
605 | aconvs _ = false; |
579 | aconvs _ = false; |
735 |
709 |
736 |
710 |
737 (*Dummy type for parsing and printing. Will be replaced during type inference. *) |
711 (*Dummy type for parsing and printing. Will be replaced during type inference. *) |
738 val dummyT = Type("dummy",[]); |
712 val dummyT = Type("dummy",[]); |
739 |
713 |
|
714 fun no_dummyT typ = |
|
715 let |
|
716 fun check (T as Type ("dummy", _)) = |
|
717 raise TYPE ("Illegal occurrence of '_' dummy type", [T], []) |
|
718 | check (Type (_, Ts)) = seq check Ts |
|
719 | check _ = (); |
|
720 in check typ; typ end; |
|
721 |
740 (*read a numeral of the given radix, normally 10*) |
722 (*read a numeral of the given radix, normally 10*) |
741 fun read_radixint (radix: int, cs) : int * string list = |
723 fun read_radixint (radix: int, cs) : int * string list = |
742 let val zero = ord"0" |
724 let val zero = ord"0" |
743 val limit = zero+radix |
725 val limit = zero+radix |
744 fun scan (num,[]) = (num,[]) |
726 fun scan (num,[]) = (num,[]) |
1119 in ((var, Free(x, T)), x) end; |
1101 in ((var, Free(x, T)), x) end; |
1120 val (insts, xs) = split_list (map mk_inst (term_vars tm)); |
1102 val (insts, xs) = split_list (map mk_inst (term_vars tm)); |
1121 in (subst_atomic insts tm, xs) end; |
1103 in (subst_atomic insts tm, xs) end; |
1122 |
1104 |
1123 |
1105 |
|
1106 (* string_of_vname *) |
|
1107 |
|
1108 fun string_of_vname (x, i) = |
|
1109 let |
|
1110 val si = string_of_int i; |
|
1111 val dot = if_none (try (Symbol.is_digit o last_elem o Symbol.explode) x) true; |
|
1112 in |
|
1113 if dot then "?" ^ x ^ "." ^ si |
|
1114 else if i = 0 then "?" ^ x |
|
1115 else "?" ^ x ^ si |
|
1116 end; |
|
1117 |
|
1118 fun string_of_vname' (x, ~1) = x |
|
1119 | string_of_vname' xi = string_of_vname xi; |
|
1120 |
1124 end; |
1121 end; |
1125 |
|
1126 |
1122 |
1127 structure BasicTerm: BASIC_TERM = Term; |
1123 structure BasicTerm: BASIC_TERM = Term; |
1128 open BasicTerm; |
1124 open BasicTerm; |