src/HOL/Tools/Function/size.ML
changeset 31784 bd3486c57ba3
parent 31775 2b04504fcb69
child 31902 862ae16a799d
equal deleted inserted replaced
31783:cfbe9609ceb1 31784:bd3486c57ba3
    42 and size_of_type' f g h T = (case size_of_type f g h T of
    42 and size_of_type' f g h T = (case size_of_type f g h T of
    43       NONE => Abs ("x", T, HOLogic.zero)
    43       NONE => Abs ("x", T, HOLogic.zero)
    44     | SOME t => t);
    44     | SOME t => t);
    45 
    45 
    46 fun is_poly thy (DtType (name, dts)) =
    46 fun is_poly thy (DtType (name, dts)) =
    47       (case Datatype.get_datatype thy name of
    47       (case Datatype.get_info thy name of
    48          NONE => false
    48          NONE => false
    49        | SOME _ => exists (is_poly thy) dts)
    49        | SOME _ => exists (is_poly thy) dts)
    50   | is_poly _ _ = true;
    50   | is_poly _ _ = true;
    51 
    51 
    52 fun constrs_of thy name =
    52 fun constrs_of thy name =
    53   let
    53   let
    54     val {descr, index, ...} = Datatype.the_datatype thy name
    54     val {descr, index, ...} = Datatype.the_info thy name
    55     val SOME (_, _, constrs) = AList.lookup op = descr index
    55     val SOME (_, _, constrs) = AList.lookup op = descr index
    56   in constrs end;
    56   in constrs end;
    57 
    57 
    58 val app = curry (list_comb o swap);
    58 val app = curry (list_comb o swap);
    59 
    59 
   218       (new_type_names ~~ size_names)) thy''
   218       (new_type_names ~~ size_names)) thy''
   219   end;
   219   end;
   220 
   220 
   221 fun add_size_thms config (new_type_names as name :: _) thy =
   221 fun add_size_thms config (new_type_names as name :: _) thy =
   222   let
   222   let
   223     val info as {descr, alt_names, ...} = Datatype.the_datatype thy name;
   223     val info as {descr, alt_names, ...} = Datatype.the_info thy name;
   224     val prefix = Long_Name.map_base_name (K (space_implode "_"
   224     val prefix = Long_Name.map_base_name (K (space_implode "_"
   225       (the_default (map Long_Name.base_name new_type_names) alt_names))) name;
   225       (the_default (map Long_Name.base_name new_type_names) alt_names))) name;
   226     val no_size = exists (fn (_, (_, _, constrs)) => exists (fn (_, cargs) => exists (fn dt =>
   226     val no_size = exists (fn (_, (_, _, constrs)) => exists (fn (_, cargs) => exists (fn dt =>
   227       is_rec_type dt andalso not (null (fst (strip_dtyp dt)))) cargs) constrs) descr
   227       is_rec_type dt andalso not (null (fst (strip_dtyp dt)))) cargs) constrs) descr
   228   in if no_size then thy
   228   in if no_size then thy