148 fun undecl_type c = "Undeclared type constructor: " ^ quote c; |
148 fun undecl_type c = "Undeclared type constructor: " ^ quote c; |
149 |
149 |
150 local |
150 local |
151 |
151 |
152 fun inst_typ env (Type (c, Ts)) = Type (c, map (inst_typ env) Ts) |
152 fun inst_typ env (Type (c, Ts)) = Type (c, map (inst_typ env) Ts) |
153 | inst_typ env (T as TFree (x, _)) = if_none (Library.assoc_string (env, x)) T |
153 | inst_typ env (T as TFree (x, _)) = if_none (AList.lookup (op =) env x) T |
154 | inst_typ _ T = T; |
154 | inst_typ _ T = T; |
155 |
155 |
156 fun certify_typ normalize syntax tsig ty = |
156 fun certify_typ normalize syntax tsig ty = |
157 let |
157 let |
158 val TSig {classes = (_, classes), types = (_, types), ...} = tsig; |
158 val TSig {classes = (_, classes), types = (_, types), ...} = tsig; |
221 let |
221 let |
222 val fs = add_term_tfrees (t, []) \\ fixed; |
222 val fs = add_term_tfrees (t, []) \\ fixed; |
223 val ixns = add_term_tvar_ixns (t, []); |
223 val ixns = add_term_tvar_ixns (t, []); |
224 val fmap = fs ~~ map (rpair 0) (variantlist (map fst fs, map #1 ixns)) |
224 val fmap = fs ~~ map (rpair 0) (variantlist (map fst fs, map #1 ixns)) |
225 fun thaw (f as (a, S)) = |
225 fun thaw (f as (a, S)) = |
226 (case gen_assoc (op =) (fmap, f) of |
226 (case AList.lookup (op =) fmap f of |
227 NONE => TFree f |
227 NONE => TFree f |
228 | SOME xi => TVar (xi, S)); |
228 | SOME xi => TVar (xi, S)); |
229 in (map_term_types (map_type_tfree thaw) t, fmap) end; |
229 in (map_term_types (map_type_tfree thaw) t, fmap) end; |
230 |
230 |
231 |
231 |
236 fun new_name (ix, (pairs, used)) = |
236 fun new_name (ix, (pairs, used)) = |
237 let val v = variant used (string_of_indexname ix) |
237 let val v = variant used (string_of_indexname ix) |
238 in ((ix, v) :: pairs, v :: used) end; |
238 in ((ix, v) :: pairs, v :: used) end; |
239 |
239 |
240 fun freeze_one alist (ix, sort) = |
240 fun freeze_one alist (ix, sort) = |
241 TFree (the (assoc_string_int (alist, ix)), sort) |
241 TFree (the (AList.lookup (op =) alist ix), sort) |
242 handle Option => |
242 handle Option => |
243 raise TYPE ("Failure during freezing of ?" ^ string_of_indexname ix, [], []); |
243 raise TYPE ("Failure during freezing of ?" ^ string_of_indexname ix, [], []); |
244 |
244 |
245 fun thaw_one alist (a, sort) = TVar (the (assoc_string (alist, a)), sort) |
245 fun thaw_one alist (a, sort) = TVar (the (AList.lookup (op =) alist a), sort) |
246 handle Option => TFree (a, sort); |
246 handle Option => TFree (a, sort); |
247 |
247 |
248 in |
248 in |
249 |
249 |
250 (*this sort of code could replace unvarifyT*) |
250 (*this sort of code could replace unvarifyT*) |
462 SOME ((c1, c2), (c', Ss')) => err_conflict pp t (SOME (c1, c2)) (c, Ss) (c', Ss') |
462 SOME ((c1, c2), (c', Ss')) => err_conflict pp t (SOME (c1, c2)) (c, Ss) (c', Ss') |
463 | NONE => (c, Ss) :: ars) |
463 | NONE => (c, Ss) :: ars) |
464 end; |
464 end; |
465 |
465 |
466 fun insert pp C t (c, Ss) ars = |
466 fun insert pp C t (c, Ss) ars = |
467 (case assoc_string (ars, c) of |
467 (case AList.lookup (op =) ars c of |
468 NONE => coregular pp C t (c, Ss) ars |
468 NONE => coregular pp C t (c, Ss) ars |
469 | SOME Ss' => |
469 | SOME Ss' => |
470 if Sorts.sorts_le C (Ss, Ss') then ars |
470 if Sorts.sorts_le C (Ss, Ss') then ars |
471 else if Sorts.sorts_le C (Ss', Ss) |
471 else if Sorts.sorts_le C (Ss', Ss) |
472 then coregular pp C t (c, Ss) (ars \ (c, Ss')) |
472 then coregular pp C t (c, Ss) (ars \ (c, Ss')) |