23 val same_sg: sg * sg -> bool |
23 val same_sg: sg * sg -> bool |
24 val is_draft: sg -> bool |
24 val is_draft: sg -> bool |
25 val const_type: sg -> string -> typ option |
25 val const_type: sg -> string -> typ option |
26 val classes: sg -> class list |
26 val classes: sg -> class list |
27 val subsort: sg -> sort * sort -> bool |
27 val subsort: sg -> sort * sort -> bool |
|
28 val nodup_Vars: term -> unit |
28 val norm_sort: sg -> sort -> sort |
29 val norm_sort: sg -> sort -> sort |
29 val nonempty_sort: sg -> sort list -> sort -> bool |
30 val nonempty_sort: sg -> sort list -> sort -> bool |
30 val print_sg: sg -> unit |
31 val print_sg: sg -> unit |
31 val pretty_sg: sg -> Pretty.T |
32 val pretty_sg: sg -> Pretty.T |
32 val pprint_sg: sg -> pprint_args -> unit |
33 val pprint_sg: sg -> pprint_args -> unit |
230 |
231 |
231 (** certify types and terms **) (*exception TYPE*) |
232 (** certify types and terms **) (*exception TYPE*) |
232 |
233 |
233 fun certify_typ (Sg {tsig, ...}) ty = cert_typ tsig ty; |
234 fun certify_typ (Sg {tsig, ...}) ty = cert_typ tsig ty; |
234 |
235 |
|
236 (* check for duplicate TVars with distinct sorts *) |
|
237 fun nodup_TVars(tvars,T) = (case T of |
|
238 Type(_,Ts) => foldl nodup_TVars (tvars,Ts) |
|
239 | TFree _ => tvars |
|
240 | TVar(v as (a,S)) => |
|
241 (case assoc(tvars,a) of |
|
242 Some(S') => if S=S' then tvars |
|
243 else raise_type |
|
244 ("Type variable "^Syntax.string_of_vname a^ |
|
245 "has two distinct sorts") [TVar(a,S'),T] [] |
|
246 | None => v::tvars)); |
|
247 |
|
248 (* check for duplicate Vars with distinct types *) |
|
249 fun nodup_Vars tm = |
|
250 let fun nodups vars tvars tm = (case tm of |
|
251 Const(c,T) => (vars, nodup_TVars(tvars,T)) |
|
252 | Free(a,T) => (vars, nodup_TVars(tvars,T)) |
|
253 | Var(v as (ixn,T)) => |
|
254 (case assoc(vars,ixn) of |
|
255 Some(T') => if T=T' then (vars,nodup_TVars(tvars,T)) |
|
256 else raise_type |
|
257 ("Variable "^Syntax.string_of_vname ixn^ |
|
258 "has two distinct types") [T',T] [] |
|
259 | None => (v::vars,tvars)) |
|
260 | Bound _ => (vars,tvars) |
|
261 | Abs(_,T,t) => nodups vars (nodup_TVars(tvars,T)) t |
|
262 | s$t => let val (vars',tvars') = nodups vars tvars s |
|
263 in nodups vars' tvars' t end); |
|
264 in nodups [] [] tm; () end; |
235 |
265 |
236 fun mapfilt_atoms f (Abs (_, _, t)) = mapfilt_atoms f t |
266 fun mapfilt_atoms f (Abs (_, _, t)) = mapfilt_atoms f t |
237 | mapfilt_atoms f (t $ u) = mapfilt_atoms f t @ mapfilt_atoms f u |
267 | mapfilt_atoms f (t $ u) = mapfilt_atoms f t @ mapfilt_atoms f u |
238 | mapfilt_atoms f a = (case f a of Some y => [y] | None => []); |
268 | mapfilt_atoms f a = (case f a of Some y => [y] | None => []); |
239 |
269 |
254 |
284 |
255 val norm_tm = |
285 val norm_tm = |
256 (case it_term_types (typ_errors tsig) (tm, []) of |
286 (case it_term_types (typ_errors tsig) (tm, []) of |
257 [] => map_term_types (norm_typ tsig) tm |
287 [] => map_term_types (norm_typ tsig) tm |
258 | errs => raise_type (cat_lines errs) [] [tm]); |
288 | errs => raise_type (cat_lines errs) [] [tm]); |
|
289 val _ = nodup_Vars norm_tm; |
259 in |
290 in |
260 (case mapfilt_atoms atom_err norm_tm of |
291 (case mapfilt_atoms atom_err norm_tm of |
261 [] => (norm_tm, type_of norm_tm, maxidx_of_term norm_tm) |
292 [] => (norm_tm, type_of norm_tm, maxidx_of_term norm_tm) |
262 | errs => raise_type (cat_lines errs) [] [norm_tm]) |
293 | errs => raise_type (cat_lines errs) [] [norm_tm]) |
263 end; |
294 end; |