src/HOL/Tools/datatype_package.ML
changeset 18964 67f572e03236
parent 18963 3adfc9dfb30a
child 18988 d6e5fa2ba8b8
equal deleted inserted replaced
18963:3adfc9dfb30a 18964:67f572e03236
   538   let
   538   let
   539     val T = Type.no_tvars (Sign.certify_typ sign raw_T) handle
   539     val T = Type.no_tvars (Sign.certify_typ sign raw_T) handle
   540       TYPE (msg, _, _) => error msg;
   540       TYPE (msg, _, _) => error msg;
   541     val sorts' = add_typ_tfrees (T, sorts)
   541     val sorts' = add_typ_tfrees (T, sorts)
   542   in (Ts @ [T],
   542   in (Ts @ [T],
   543       case gen_duplicates (op =) (map fst sorts') of
   543       case duplicates (op =) (map fst sorts') of
   544          [] => sorts'
   544          [] => sorts'
   545        | dups => error ("Inconsistent sort constraints for " ^ commas dups))
   545        | dups => error ("Inconsistent sort constraints for " ^ commas dups))
   546   end;
   546   end;
   547 
   547 
   548 
   548 
   930     val sign = Theory.sign_of tmp_thy;
   930     val sign = Theory.sign_of tmp_thy;
   931 
   931 
   932     val (tyvars, _, _, _)::_ = dts;
   932     val (tyvars, _, _, _)::_ = dts;
   933     val (new_dts, types_syntax) = ListPair.unzip (map (fn (tvs, tname, mx, _) =>
   933     val (new_dts, types_syntax) = ListPair.unzip (map (fn (tvs, tname, mx, _) =>
   934       let val full_tname = Sign.full_name sign (Syntax.type_name tname mx)
   934       let val full_tname = Sign.full_name sign (Syntax.type_name tname mx)
   935       in (case gen_duplicates (op =) tvs of
   935       in (case duplicates (op =) tvs of
   936             [] => if eq_set (tyvars, tvs) then ((full_tname, tvs), (tname, mx))
   936             [] => if eq_set (tyvars, tvs) then ((full_tname, tvs), (tname, mx))
   937                   else error ("Mutually recursive datatypes must have same type parameters")
   937                   else error ("Mutually recursive datatypes must have same type parameters")
   938           | dups => error ("Duplicate parameter(s) for datatype " ^ full_tname ^
   938           | dups => error ("Duplicate parameter(s) for datatype " ^ full_tname ^
   939               " : " ^ commas dups))
   939               " : " ^ commas dups))
   940       end) dts);
   940       end) dts);
   941 
   941 
   942     val _ = (case gen_duplicates (op =) (map fst new_dts) @ gen_duplicates (op =) new_type_names of
   942     val _ = (case duplicates (op =) (map fst new_dts) @ duplicates (op =) new_type_names of
   943       [] => () | dups => error ("Duplicate datatypes: " ^ commas dups));
   943       [] => () | dups => error ("Duplicate datatypes: " ^ commas dups));
   944 
   944 
   945     fun prep_dt_spec ((dts', constr_syntax, sorts, i), (tvs, tname, mx, constrs)) =
   945     fun prep_dt_spec ((dts', constr_syntax, sorts, i), (tvs, tname, mx, constrs)) =
   946       let
   946       let
   947         fun prep_constr ((constrs, constr_syntax', sorts'), (cname, cargs, mx')) =
   947         fun prep_constr ((constrs, constr_syntax', sorts'), (cname, cargs, mx')) =
   960 
   960 
   961         val (constrs', constr_syntax', sorts') =
   961         val (constrs', constr_syntax', sorts') =
   962           Library.foldl prep_constr (([], [], sorts), constrs)
   962           Library.foldl prep_constr (([], [], sorts), constrs)
   963 
   963 
   964       in
   964       in
   965         case gen_duplicates (op =) (map fst constrs') of
   965         case duplicates (op =) (map fst constrs') of
   966            [] =>
   966            [] =>
   967              (dts' @ [(i, (Sign.full_name sign (Syntax.type_name tname mx),
   967              (dts' @ [(i, (Sign.full_name sign (Syntax.type_name tname mx),
   968                 map DtTFree tvs, constrs'))],
   968                 map DtTFree tvs, constrs'))],
   969               constr_syntax @ [constr_syntax'], sorts', i + 1)
   969               constr_syntax @ [constr_syntax'], sorts', i + 1)
   970          | dups => error ("Duplicate constructors " ^ commas dups ^
   970          | dups => error ("Duplicate constructors " ^ commas dups ^