src/HOL/Tools/Datatype/datatype_data.ML
changeset 42359 6ca5407863ed
parent 42297 140f283266b7
child 42361 23f352990944
equal deleted inserted replaced
42358:b47d41d9f4b5 42359:6ca5407863ed
   376          induct inject distinct
   376          induct inject distinct
   377  end;
   377  end;
   378 
   378 
   379 fun gen_rep_datatype prep_term config after_qed alt_names raw_ts thy =
   379 fun gen_rep_datatype prep_term config after_qed alt_names raw_ts thy =
   380   let
   380   let
       
   381     val ctxt = ProofContext.init_global thy;
       
   382 
   381     fun constr_of_term (Const (c, T)) = (c, T)
   383     fun constr_of_term (Const (c, T)) = (c, T)
   382       | constr_of_term t =
   384       | constr_of_term t = error ("Not a constant: " ^ Syntax.string_of_term ctxt t);
   383           error ("Not a constant: " ^ Syntax.string_of_term_global thy t);
   385     fun no_constr (c, T) =
   384     fun no_constr (c, T) = error ("Bad constructor: "
   386       error ("Bad constructor: " ^ ProofContext.extern_const ctxt c ^ "::" ^
   385       ^ Sign.extern_const thy c ^ "::"
   387         Syntax.string_of_typ ctxt T);
   386       ^ Syntax.string_of_typ_global thy T);
       
   387     fun type_of_constr (cT as (_, T)) =
   388     fun type_of_constr (cT as (_, T)) =
   388       let
   389       let
   389         val frees = OldTerm.typ_tfrees T;
   390         val frees = OldTerm.typ_tfrees T;
   390         val (tyco, vs) = (apsnd o map) dest_TFree (dest_Type (body_type T))
   391         val (tyco, vs) = (apsnd o map) dest_TFree (dest_Type (body_type T))
   391           handle TYPE _ => no_constr cT
   392           handle TYPE _ => no_constr cT
   435           (prove_rep_datatype config dt_names alt_names descr vs
   436           (prove_rep_datatype config dt_names alt_names descr vs
   436             raw_inject half_distinct raw_induct)
   437             raw_inject half_distinct raw_induct)
   437         #-> after_qed
   438         #-> after_qed
   438       end;
   439       end;
   439   in
   440   in
   440     thy
   441     ctxt
   441     |> ProofContext.init_global
       
   442     |> Proof.theorem NONE after_qed' ((map o map) (rpair []) (flat rules))
   442     |> Proof.theorem NONE after_qed' ((map o map) (rpair []) (flat rules))
   443   end;
   443   end;
   444 
   444 
   445 val rep_datatype = gen_rep_datatype Sign.cert_term;
   445 val rep_datatype = gen_rep_datatype Sign.cert_term;
   446 val rep_datatype_cmd = gen_rep_datatype Syntax.read_term_global Datatype_Aux.default_config (K I);
   446 val rep_datatype_cmd = gen_rep_datatype Syntax.read_term_global Datatype_Aux.default_config (K I);