src/HOL/Tools/Datatype/datatype.ML
changeset 44121 44adaa6db327
parent 42381 309ec68442c6
child 44241 7943b69f0188
equal deleted inserted replaced
44120:01de796250a0 44121:44adaa6db327
    75     val branchTs = Datatype_Aux.get_branching_types descr' sorts;
    75     val branchTs = Datatype_Aux.get_branching_types descr' sorts;
    76     val branchT = if null branchTs then HOLogic.unitT
    76     val branchT = if null branchTs then HOLogic.unitT
    77       else Balanced_Tree.make (fn (T, U) => Type (@{type_name Sum_Type.sum}, [T, U])) branchTs;
    77       else Balanced_Tree.make (fn (T, U) => Type (@{type_name Sum_Type.sum}, [T, U])) branchTs;
    78     val arities = remove (op =) 0 (Datatype_Aux.get_arities descr');
    78     val arities = remove (op =) 0 (Datatype_Aux.get_arities descr');
    79     val unneeded_vars =
    79     val unneeded_vars =
    80       subtract (op =) (List.foldr OldTerm.add_typ_tfree_names [] (leafTs' @ branchTs)) (hd tyvars);
    80       subtract (op =) (List.foldr Misc_Legacy.add_typ_tfree_names [] (leafTs' @ branchTs)) (hd tyvars);
    81     val leafTs = leafTs' @ map (fn n => TFree (n, (the o AList.lookup (op =) sorts) n)) unneeded_vars;
    81     val leafTs = leafTs' @ map (fn n => TFree (n, (the o AList.lookup (op =) sorts) n)) unneeded_vars;
    82     val recTs = Datatype_Aux.get_rec_types descr' sorts;
    82     val recTs = Datatype_Aux.get_rec_types descr' sorts;
    83     val (newTs, oldTs) = chop (length (hd descr)) recTs;
    83     val (newTs, oldTs) = chop (length (hd descr)) recTs;
    84     val sumT = if null leafTs then HOLogic.unitT
    84     val sumT = if null leafTs then HOLogic.unitT
    85       else Balanced_Tree.make (fn (T, U) => Type (@{type_name Sum_Type.sum}, [T, U])) leafTs;
    85       else Balanced_Tree.make (fn (T, U) => Type (@{type_name Sum_Type.sum}, [T, U])) leafTs;
   370     fun mk_funs_inv thy thm =
   370     fun mk_funs_inv thy thm =
   371       let
   371       let
   372         val prop = Thm.prop_of thm;
   372         val prop = Thm.prop_of thm;
   373         val _ $ (_ $ ((S as Const (_, Type (_, [U, _]))) $ _ )) $
   373         val _ $ (_ $ ((S as Const (_, Type (_, [U, _]))) $ _ )) $
   374           (_ $ (_ $ (r $ (a $ _)) $ _)) = Type.legacy_freeze prop;
   374           (_ $ (_ $ (r $ (a $ _)) $ _)) = Type.legacy_freeze prop;
   375         val used = OldTerm.add_term_tfree_names (a, []);
   375         val used = Misc_Legacy.add_term_tfree_names (a, []);
   376 
   376 
   377         fun mk_thm i =
   377         fun mk_thm i =
   378           let
   378           let
   379             val Ts = map (TFree o rpair HOLogic.typeS)
   379             val Ts = map (TFree o rpair HOLogic.typeS)
   380               (Name.variant_list used (replicate i "'t"));
   380               (Name.variant_list used (replicate i "'t"));
   674       let
   674       let
   675         fun prep_constr (cname, cargs, mx') (constrs, constr_syntax', sorts') =
   675         fun prep_constr (cname, cargs, mx') (constrs, constr_syntax', sorts') =
   676           let
   676           let
   677             val (cargs', sorts'') = fold_map (prep_typ tmp_thy) cargs sorts';
   677             val (cargs', sorts'') = fold_map (prep_typ tmp_thy) cargs sorts';
   678             val _ =
   678             val _ =
   679               (case subtract (op =) tvs (fold (curry OldTerm.add_typ_tfree_names) cargs' []) of
   679               (case subtract (op =) tvs (fold (curry Misc_Legacy.add_typ_tfree_names) cargs' []) of
   680                 [] => ()
   680                 [] => ()
   681               | vs => error ("Extra type variables on rhs: " ^ commas vs));
   681               | vs => error ("Extra type variables on rhs: " ^ commas vs));
   682             val c = Sign.full_name_path tmp_thy tname' cname;
   682             val c = Sign.full_name_path tmp_thy tname' cname;
   683           in
   683           in
   684             (constrs @ [(c, map (Datatype_Aux.dtyp_of_typ new_dts) cargs')],
   684             (constrs @ [(c, map (Datatype_Aux.dtyp_of_typ new_dts) cargs')],