src/HOL/thy_data.ML
author clasohm
Fri Apr 19 11:33:24 1996 +0200 (1996-04-19)
changeset 1668 8ead1fe65aad
parent 1657 a7a6c3fb3cdd
child 1726 cbea219f5e5a
permissions -rw-r--r--
added Konrad's code for the datatype package
clasohm@1465
     1
(*  Title:      HOL/thy_data.ML
clasohm@1455
     2
    ID:         $Id$
clasohm@1465
     3
    Author:     Carsten Clasohm
clasohm@1455
     4
    Copyright   1995 TU Muenchen
clasohm@1455
     5
clasohm@1455
     6
Definitions that have to be reread after init_thy_reader has been invoked
clasohm@1455
     7
*)
clasohm@1455
     8
clasohm@1455
     9
fun simpset_of tname =
clasohm@1657
    10
  case get_thydata tname "simpset" of
clasohm@1455
    11
      None => empty_ss
clasohm@1455
    12
    | Some (SS_DATA ss) => ss;
clasohm@1455
    13
clasohm@1668
    14
clasohm@1668
    15
(** Information about datatypes **)
clasohm@1668
    16
clasohm@1668
    17
(* Retrieve information for a specific datatype *)
clasohm@1668
    18
fun datatype_info thy tname =
clasohm@1668
    19
  case get_thydata (thyname_of_sign (sign_of thy)) "datatypes" of
clasohm@1668
    20
      None => None
clasohm@1668
    21
    | Some (DT_DATA ds) => assoc (ds, tname);
clasohm@1668
    22
clasohm@1668
    23
fun match_info thy tname =
clasohm@1668
    24
  case datatype_info thy tname of
clasohm@1668
    25
      Some {case_const, constructors, ...} =>
clasohm@1668
    26
        {case_const=case_const, constructors=constructors}
clasohm@1668
    27
    | None => error ("No datatype \"" ^ tname ^ "\" defined in this theory.");
clasohm@1668
    28
clasohm@1668
    29
fun induct_info thy tname =
clasohm@1668
    30
  case datatype_info thy tname of
clasohm@1668
    31
      Some {constructors, nchotomy, ...} =>
clasohm@1668
    32
        {constructors=constructors, nchotomy=nchotomy}
clasohm@1668
    33
    | None => error ("No datatype \"" ^ tname ^ "\" defined in this theory.");
clasohm@1668
    34
clasohm@1668
    35
clasohm@1668
    36
(* Retrieve information for all datatypes defined in a theory and its
clasohm@1668
    37
   ancestors *)
clasohm@1668
    38
fun extract_info thy =
clasohm@1668
    39
  let val (congs, rewrites) =
clasohm@1668
    40
        case get_thydata (thyname_of_sign (sign_of thy)) "datatypes" of
clasohm@1668
    41
            None => ([], [])
clasohm@1668
    42
          | Some (DT_DATA ds) =>
clasohm@1668
    43
              let val info = map snd ds
clasohm@1668
    44
              in (map #case_cong info, flat (map #case_rewrites info)) end;
clasohm@1668
    45
  in {case_congs = congs, case_rewrites = rewrites} end;