src/HOL/datatype.ML
changeset 3979 dac05c9341f4
parent 3945 ae9c61d69888
child 4032 4b1c69d8b767
equal deleted inserted replaced
3978:7e1cfed19d94 3979:dac05c9341f4
     8 
     8 
     9 (** Information about datatypes **)
     9 (** Information about datatypes **)
    10 
    10 
    11 (* Retrieve information for a specific datatype *)
    11 (* Retrieve information for a specific datatype *)
    12 fun datatype_info thy tname =
    12 fun datatype_info thy tname =
    13   case get_thydata (thyname_of_sign (sign_of thy)) "datatypes" of
    13   case get_thydata (Sign.name_of (sign_of thy)) "datatypes" of
    14       None => None
    14       None => None
    15     | Some (DT_DATA ds) => assoc (ds, tname);
    15     | Some (DT_DATA ds) => assoc (ds, tname);
    16 
    16 
    17 fun match_info thy tname =
    17 fun match_info thy tname =
    18   case datatype_info thy tname of
    18   case datatype_info thy tname of
    29 
    29 
    30 (* Retrieve information for all datatypes defined in a theory and its
    30 (* Retrieve information for all datatypes defined in a theory and its
    31    ancestors *)
    31    ancestors *)
    32 fun extract_info thy =
    32 fun extract_info thy =
    33   let val (congs, rewrites) =
    33   let val (congs, rewrites) =
    34         case get_thydata (thyname_of_sign (sign_of thy)) "datatypes" of
    34         case get_thydata (Sign.name_of (sign_of thy)) "datatypes" of
    35             None => ([], [])
    35             None => ([], [])
    36           | Some (DT_DATA ds) =>
    36           | Some (DT_DATA ds) =>
    37               let val info = map snd ds
    37               let val info = map snd ds
    38               in (map #case_cong info, flat (map #case_rewrites info)) end;
    38               in (map #case_cong info, flat (map #case_rewrites info)) end;
    39   in {case_congs = congs, case_rewrites = rewrites} end;
    39   in {case_congs = congs, case_rewrites = rewrites} end;
    48      | Some(Type(tn,_)) => tn
    48      | Some(Type(tn,_)) => tn
    49      | _ => error("Cannot induct on type of " ^ quote var)
    49      | _ => error("Cannot induct on type of " ^ quote var)
    50   end;
    50   end;
    51 
    51 
    52 fun get_dt_info sign tn =
    52 fun get_dt_info sign tn =
    53       case get_thydata (thyname_of_sign sign) "datatypes" of
    53       case get_thydata (Sign.name_of sign) "datatypes" of
    54         None => error ("No such datatype: " ^ quote tn)
    54         None => error ("No such datatype: " ^ quote tn)
    55       | Some (DT_DATA ds) =>
    55       | Some (DT_DATA ds) =>
    56           case assoc (ds, tn) of
    56           case assoc (ds, tn) of
    57             Some info => info
    57             Some info => info
    58           | None => error ("Not a datatype: " ^ quote tn)
    58           | None => error ("Not a datatype: " ^ quote tn)