431 val ty' = map_type_tfree (fn (v, _) => TFree (the_v v)) ty; |
431 val ty' = map_type_tfree (fn (v, _) => TFree (the_v v)) ty; |
432 val (vs'', _) = logical_typscheme thy (c, ty'); |
432 val (vs'', _) = logical_typscheme thy (c, ty'); |
433 in (c, (vs'', binder_types ty')) end; |
433 in (c, (vs'', binder_types ty')) end; |
434 val c' :: cs' = map (analyze_constructor thy) cs; |
434 val c' :: cs' = map (analyze_constructor thy) cs; |
435 val ((tyco, sorts), cs'') = fold add cs' (apsnd single c'); |
435 val ((tyco, sorts), cs'') = fold add cs' (apsnd single c'); |
436 val vs = Name.names Name.context Name.aT sorts; |
436 val vs = Name.invent_names Name.context Name.aT sorts; |
437 val cs''' = map (inst vs) cs''; |
437 val cs''' = map (inst vs) cs''; |
438 in (tyco, (vs, rev cs''')) end; |
438 in (tyco, (vs, rev cs''')) end; |
439 |
439 |
440 fun get_type_entry thy tyco = case these (Symtab.lookup ((the_types o the_exec) thy) tyco) |
440 fun get_type_entry thy tyco = case these (Symtab.lookup ((the_types o the_exec) thy) tyco) |
441 of (_, entry) :: _ => SOME entry |
441 of (_, entry) :: _ => SOME entry |
442 | _ => NONE; |
442 | _ => NONE; |
443 |
443 |
444 fun get_type thy tyco = case get_type_entry thy tyco |
444 fun get_type thy tyco = case get_type_entry thy tyco |
445 of SOME (vs, spec) => apfst (pair vs) (constructors_of spec) |
445 of SOME (vs, spec) => apfst (pair vs) (constructors_of spec) |
446 | NONE => arity_number thy tyco |
446 | NONE => arity_number thy tyco |
447 |> Name.invents Name.context Name.aT |
447 |> Name.invent Name.context Name.aT |
448 |> map (rpair []) |
448 |> map (rpair []) |
449 |> rpair [] |
449 |> rpair [] |
450 |> rpair false; |
450 |> rpair false; |
451 |
451 |
452 fun get_abstype_spec thy tyco = case get_type_entry thy tyco |
452 fun get_abstype_spec thy tyco = case get_type_entry thy tyco |
777 fun tvars_of T = rev (Term.add_tvarsT T []); |
777 fun tvars_of T = rev (Term.add_tvarsT T []); |
778 val vss = map (tvars_of o snd o head_eqn) thms; |
778 val vss = map (tvars_of o snd o head_eqn) thms; |
779 fun inter_sorts vs = |
779 fun inter_sorts vs = |
780 fold (curry (Sorts.inter_sort (Sign.classes_of thy)) o snd) vs []; |
780 fold (curry (Sorts.inter_sort (Sign.classes_of thy)) o snd) vs []; |
781 val sorts = map_transpose inter_sorts vss; |
781 val sorts = map_transpose inter_sorts vss; |
782 val vts = Name.names Name.context Name.aT sorts; |
782 val vts = Name.invent_names Name.context Name.aT sorts; |
783 val thms' = |
783 val thms' = |
784 map2 (fn vs => Thm.certify_instantiate (vs ~~ map TFree vts, [])) vss thms; |
784 map2 (fn vs => Thm.certify_instantiate (vs ~~ map TFree vts, [])) vss thms; |
785 val head_thm = Thm.symmetric (Thm.assume (build_head thy (head_eqn (hd thms')))); |
785 val head_thm = Thm.symmetric (Thm.assume (build_head thy (head_eqn (hd thms')))); |
786 fun head_conv ct = if can Thm.dest_comb ct |
786 fun head_conv ct = if can Thm.dest_comb ct |
787 then Conv.fun_conv head_conv ct |
787 then Conv.fun_conv head_conv ct |