54 val name_arities: arity -> string list |
54 val name_arities: arity -> string list |
55 val name_arity: string * sort list * class -> string |
55 val name_arity: string * sort list * class -> string |
56 val mk_arities: arity -> term list |
56 val mk_arities: arity -> term list |
57 val mk_arity: string * sort list * class -> term |
57 val mk_arity: string * sort list * class -> term |
58 val dest_arity: term -> string * sort list * class |
58 val dest_arity: term -> string * sort list * class |
|
59 val dummy_tfree: sort -> typ |
59 type unconstrain_context = |
60 type unconstrain_context = |
60 {present_map: (typ * typ) list, |
61 {present_map: (typ * typ) list, |
61 constraints_map: (sort * typ) list, |
62 constraints_map: (sort * typ) list, |
62 atyp_map: typ -> typ, |
63 atyp_map: typ -> typ, |
63 map_atyps: typ -> typ, |
64 map_atyps: typ -> typ, |
|
65 map_atyps': typ -> typ, |
64 constraints: ((typ * class) * term) list, |
66 constraints: ((typ * class) * term) list, |
65 outer_constraints: (typ * class) list}; |
67 outer_constraints: (typ * class) list}; |
66 val unconstrainT: sort list -> term -> unconstrain_context * term |
68 val unconstrainT: sort list -> term -> unconstrain_context * term |
67 val protectC: term |
69 val protectC: term |
68 val protect: term -> term |
70 val protect: term -> term |
343 in (t, Ss, c) end; |
346 in (t, Ss, c) end; |
344 |
347 |
345 |
348 |
346 (* internalized sort constraints *) |
349 (* internalized sort constraints *) |
347 |
350 |
|
351 fun dummy_tfree S = TFree ("'dummy", S); |
|
352 |
348 type unconstrain_context = |
353 type unconstrain_context = |
349 {present_map: (typ * typ) list, |
354 {present_map: (typ * typ) list, |
350 constraints_map: (sort * typ) list, |
355 constraints_map: (sort * typ) list, |
351 atyp_map: typ -> typ, |
356 atyp_map: typ -> typ, |
352 map_atyps: typ -> typ, |
357 map_atyps: typ -> typ, |
|
358 map_atyps': typ -> typ, |
353 constraints: ((typ * class) * term) list, |
359 constraints: ((typ * class) * term) list, |
354 outer_constraints: (typ * class) list}; |
360 outer_constraints: (typ * class) list}; |
355 |
361 |
356 fun unconstrainT shyps prop = |
362 fun unconstrainT shyps prop = |
357 let |
363 let |
364 val present_map = |
370 val present_map = |
365 map2 (fn (T, S) => fn a => (T, TVar ((a, 0), S))) present names1; |
371 map2 (fn (T, S) => fn a => (T, TVar ((a, 0), S))) present names1; |
366 val constraints_map = |
372 val constraints_map = |
367 map2 (fn (_, S) => fn a => (S, TVar ((a, 0), S))) present names1 @ |
373 map2 (fn (_, S) => fn a => (S, TVar ((a, 0), S))) present names1 @ |
368 map2 (fn S => fn a => (S, TVar ((a, 0), S))) extra names2; |
374 map2 (fn S => fn a => (S, TVar ((a, 0), S))) extra names2; |
|
375 |
|
376 val present_map' = map (fn (T, T') => (Type.strip_sorts T', T)) present_map; |
|
377 val constraints_map' = map (fn (S, T') => (Type.strip_sorts T', dummy_tfree S)) constraints_map; |
369 |
378 |
370 fun atyp_map T = |
379 fun atyp_map T = |
371 (case AList.lookup (op =) present_map T of |
380 (case AList.lookup (op =) present_map T of |
372 SOME U => U |
381 SOME U => U |
373 | NONE => |
382 | NONE => |
374 (case AList.lookup (op =) constraints_map (Type.sort_of_atyp T) of |
383 (case AList.lookup (op =) constraints_map (Type.sort_of_atyp T) of |
375 SOME U => U |
384 SOME U => U |
376 | NONE => raise TYPE ("Dangling type variable", [T], []))); |
385 | NONE => raise TYPE ("Dangling type variable ", [T], [prop]))); |
|
386 |
|
387 fun atyp_map' T = |
|
388 (case AList.lookup (op =) present_map' T of |
|
389 SOME U => U |
|
390 | NONE => |
|
391 (case AList.lookup (op =) constraints_map' T of |
|
392 SOME U => U |
|
393 | NONE => raise TYPE ("Dangling type variable", [T], [prop]))); |
|
394 |
|
395 val map_atyps = Term.map_atyps (Type.strip_sorts o atyp_map); |
|
396 val map_atyps' = Term.map_atyps atyp_map'; |
377 |
397 |
378 val constraints = |
398 val constraints = |
379 constraints_map |> maps (fn (_, T as TVar (ai, S)) => |
399 constraints_map |> maps (fn (_, T as TVar (ai, S)) => |
380 map (fn c => ((T, c), mk_of_class (TVar (ai, []), c))) S); |
400 map (fn c => ((T, c), mk_of_class (TVar (ai, []), c))) S); |
381 |
401 |
382 val outer_constraints = |
402 val outer_constraints = |
383 maps (fn (T, S) => map (pair T) S) |
403 maps (fn (T, S) => map (pair T) S) (present @ map (`dummy_tfree) extra); |
384 (present @ map (fn S => (TFree ("'dummy", S), S)) extra); |
404 |
385 |
|
386 val map_atyps = Term.map_atyps (Type.strip_sorts o atyp_map); |
|
387 val ucontext = |
405 val ucontext = |
388 {present_map = present_map, |
406 {present_map = present_map, |
389 constraints_map = constraints_map, |
407 constraints_map = constraints_map, |
390 atyp_map = atyp_map, |
408 atyp_map = atyp_map, |
391 map_atyps = map_atyps, |
409 map_atyps = map_atyps, |
|
410 map_atyps' = map_atyps', |
392 constraints = constraints, |
411 constraints = constraints, |
393 outer_constraints = outer_constraints}; |
412 outer_constraints = outer_constraints}; |
394 val prop' = prop |
413 val prop' = prop |
395 |> Term.map_types map_atyps |
414 |> Term.map_types map_atyps |
396 |> curry list_implies (map #2 constraints); |
415 |> curry list_implies (map #2 constraints); |