src/HOL/Tools/datatype_package.ML
changeset 31247 71f163982a21
parent 31208 1ef2f0af7f26
child 31361 3e900a2acaed
equal deleted inserted replaced
31246:251a34663242 31247:71f163982a21
    14   val datatype_of_constr : theory -> string -> DatatypeAux.datatype_info option
    14   val datatype_of_constr : theory -> string -> DatatypeAux.datatype_info option
    15   val datatype_of_case : theory -> string -> DatatypeAux.datatype_info option
    15   val datatype_of_case : theory -> string -> DatatypeAux.datatype_info option
    16   val the_datatype_spec : theory -> string -> (string * sort) list * (string * typ list) list
    16   val the_datatype_spec : theory -> string -> (string * sort) list * (string * typ list) list
    17   val get_datatype_constrs : theory -> string -> (string * typ) list option
    17   val get_datatype_constrs : theory -> string -> (string * typ) list option
    18   val construction_interpretation : theory
    18   val construction_interpretation : theory
    19     -> {atom : typ -> 'a, dtyp : string -> 'a, rtyp : string -> 'a list -> 'a}
    19     -> {atom : typ -> 'a, dtyp : string -> 'a, rtyp : string * typ list -> 'a list -> 'a}
    20     -> (string * sort) list -> string list
    20     -> (string * sort) list -> string list
    21     -> (string * (string * 'a list) list) list
    21     -> (string * (string * 'a list) list) list
       
    22       * ((string * typ list) * (string * 'a list) list) list
    22   val distinct_simproc : simproc
    23   val distinct_simproc : simproc
    23   val make_case :  Proof.context -> bool -> string list -> term ->
    24   val make_case :  Proof.context -> bool -> string list -> term ->
    24     (term * term) list -> term * (term * (int * bool)) list
    25     (term * term) list -> term * (term * (int * bool)) list
    25   val strip_case : Proof.context -> bool -> term -> (term * (term * term) list) option
    26   val strip_case : Proof.context -> bool -> term -> (term * (term * term) list) option
    26   val read_typ: theory ->
    27   val read_typ: theory ->
   147 fun construction_interpretation thy { atom, dtyp, rtyp } sorts tycos =
   148 fun construction_interpretation thy { atom, dtyp, rtyp } sorts tycos =
   148   let
   149   let
   149     val descr = (#descr o the_datatype thy o hd) tycos;
   150     val descr = (#descr o the_datatype thy o hd) tycos;
   150     val k = length tycos;
   151     val k = length tycos;
   151     val descr_of = the o AList.lookup (op =) descr;
   152     val descr_of = the o AList.lookup (op =) descr;
   152     fun interpT (T as DtTFree _) = atom (typ_of_dtyp descr sorts T)
   153     val typ_of_dtyp = typ_of_dtyp descr sorts;
   153       | interpT (T as DtType (tyco, Ts)) = if is_rec_type T
   154     fun interpT (dT as DtTFree _) = atom (typ_of_dtyp dT)
   154           then rtyp tyco (map interpT Ts)
   155       | interpT (dT as DtType (tyco, dTs)) = 
   155           else atom (typ_of_dtyp descr sorts T)
   156           let
       
   157             val Ts = map typ_of_dtyp dTs;
       
   158           in if is_rec_type dT
       
   159             then rtyp (tyco, Ts) (map interpT dTs)
       
   160             else atom (Type (tyco, Ts))
       
   161           end
   156       | interpT (DtRec l) = if l < k then (dtyp o #1 o descr_of) l
   162       | interpT (DtRec l) = if l < k then (dtyp o #1 o descr_of) l
   157           else let val (tyco, Ts, _) = descr_of l
   163           else let
   158           in rtyp tyco (map interpT Ts) end;
   164             val (tyco, dTs, _) = descr_of l;
   159     fun interpC (c, Ts) = (c, map interpT Ts);
   165             val Ts = map typ_of_dtyp dTs;
   160     fun interpK (_, (tyco, _, cs)) = (tyco, map interpC cs);
   166           in rtyp (tyco, Ts) (map interpT dTs) end;
   161   in map interpK (Library.take (k, descr)) end;
   167     fun interpC (c, dTs) = (c, map interpT dTs);
       
   168     fun interpD (_, (tyco, _, cs)) = (tyco, map interpC cs);
       
   169     fun interpR (_, (tyco, dTs, cs)) = ((tyco, map typ_of_dtyp dTs), map interpC cs);
       
   170   in chop k descr |> (apfst o map) interpD |> (apsnd o map) interpR end;
   162 
   171 
   163 
   172 
   164 
   173 
   165 (** induct method setup **)
   174 (** induct method setup **)
   166 
   175