src/HOL/Typedef.thy
changeset 26151 4a9b8f15ce7f
parent 25535 4975b7529a14
child 26802 9eede540a5e8
equal deleted inserted replaced
26150:f6bd8686b71e 26151:4a9b8f15ce7f
   112   TypedefPackage.setup
   112   TypedefPackage.setup
   113   #> TypecopyPackage.setup
   113   #> TypecopyPackage.setup
   114   #> TypedefCodegen.setup
   114   #> TypedefCodegen.setup
   115 *}
   115 *}
   116 
   116 
       
   117 text {* This class is just a workaround for classes without parameters;
       
   118   it shall disappear as soon as possible. *}
       
   119 
       
   120 class itself = type + 
       
   121   fixes itself :: "'a itself"
       
   122 
       
   123 setup {*
       
   124 let fun add_itself tyco thy =
       
   125   let
       
   126     val vs = Name.names Name.context "'a"
       
   127       (replicate (Sign.arity_number thy tyco) @{sort type});
       
   128     val ty = Type (tyco, map TFree vs);
       
   129     val lhs = Const (@{const_name itself}, Term.itselfT ty);
       
   130     val rhs = Logic.mk_type ty;
       
   131     val eq = HOLogic.mk_Trueprop (HOLogic.mk_eq (lhs, rhs));
       
   132   in
       
   133     thy
       
   134     |> TheoryTarget.instantiation ([tyco], vs, @{sort itself})
       
   135     |> `(fn lthy => Syntax.check_term lthy eq)
       
   136     |-> (fn eq => Specification.definition (NONE, (("", []), eq)))
       
   137     |> snd
       
   138     |> Class.prove_instantiation_instance (K (Class.intro_classes_tac []))
       
   139     |> LocalTheory.exit
       
   140     |> ProofContext.theory_of
       
   141   end
       
   142 in TypedefPackage.interpretation add_itself end
       
   143 *}
       
   144 
       
   145 instantiation bool :: itself
       
   146 begin
       
   147 
       
   148 definition "itself = TYPE(bool)"
       
   149 
       
   150 instance ..
       
   151 
   117 end
   152 end
       
   153 
       
   154 instantiation "fun" :: ("type", "type") itself
       
   155 begin
       
   156 
       
   157 definition "itself = TYPE('a \<Rightarrow> 'b)"
       
   158 
       
   159 instance ..
       
   160 
       
   161 end
       
   162 
       
   163 instantiation "set" :: ("type") itself
       
   164 begin
       
   165 
       
   166 definition "itself = TYPE('a set)"
       
   167 
       
   168 instance ..
       
   169 
       
   170 end
       
   171 
       
   172 hide (open) const itself
       
   173 
       
   174 end