490 fun no_constr (c, T) = error ("Bad constructor: " |
489 fun no_constr (c, T) = error ("Bad constructor: " |
491 ^ Sign.extern_const thy c ^ "::" |
490 ^ Sign.extern_const thy c ^ "::" |
492 ^ Syntax.string_of_typ_global thy T); |
491 ^ Syntax.string_of_typ_global thy T); |
493 fun type_of_constr (cT as (_, T)) = |
492 fun type_of_constr (cT as (_, T)) = |
494 let |
493 let |
495 val frees = typ_tfrees T; |
494 val frees = OldTerm.typ_tfrees T; |
496 val (tyco, vs) = ((apsnd o map) (dest_TFree) o dest_Type o snd o strip_type) T |
495 val (tyco, vs) = ((apsnd o map) (dest_TFree) o dest_Type o snd o strip_type) T |
497 handle TYPE _ => no_constr cT |
496 handle TYPE _ => no_constr cT |
498 val _ = if has_duplicates (eq_fst (op =)) vs then no_constr cT else (); |
497 val _ = if has_duplicates (eq_fst (op =)) vs then no_constr cT else (); |
499 val _ = if length frees <> length vs then no_constr cT else (); |
498 val _ = if length frees <> length vs then no_constr cT else (); |
500 in (tyco, (vs, cT)) end; |
499 in (tyco, (vs, cT)) end; |
581 fun prep_dt_spec (tvs, tname, mx, constrs) (dts', constr_syntax, sorts, i) = |
580 fun prep_dt_spec (tvs, tname, mx, constrs) (dts', constr_syntax, sorts, i) = |
582 let |
581 let |
583 fun prep_constr (cname, cargs, mx') (constrs, constr_syntax', sorts') = |
582 fun prep_constr (cname, cargs, mx') (constrs, constr_syntax', sorts') = |
584 let |
583 let |
585 val (cargs', sorts'') = Library.foldl (prep_typ tmp_thy) (([], sorts'), cargs); |
584 val (cargs', sorts'') = Library.foldl (prep_typ tmp_thy) (([], sorts'), cargs); |
586 val _ = (case fold (curry add_typ_tfree_names) cargs' [] \\ tvs of |
585 val _ = (case fold (curry OldTerm.add_typ_tfree_names) cargs' [] \\ tvs of |
587 [] => () |
586 [] => () |
588 | vs => error ("Extra type variables on rhs: " ^ commas vs)) |
587 | vs => error ("Extra type variables on rhs: " ^ commas vs)) |
589 in (constrs @ [((if flat_names then Sign.full_bname tmp_thy else |
588 in (constrs @ [((if flat_names then Sign.full_bname tmp_thy else |
590 Sign.full_bname_path tmp_thy tname) (Syntax.const_name cname mx'), |
589 Sign.full_bname_path tmp_thy tname) (Syntax.const_name cname mx'), |
591 map (dtyp_of_typ new_dts) cargs')], |
590 map (dtyp_of_typ new_dts) cargs')], |