src/HOL/Tools/function_package/fundef_package.ML
changeset 21235 674e2731b519
parent 21211 5370cfbf3070
child 21237 b803f9870e97
equal deleted inserted replaced
21234:fb84ab52f23b 21235:674e2731b519
    25 
    25 
    26     val cong_add: attribute
    26     val cong_add: attribute
    27     val cong_del: attribute
    27     val cong_del: attribute
    28 
    28 
    29     val setup : theory -> theory
    29     val setup : theory -> theory
       
    30     val setup_case_cong_hook : theory -> theory
    30     val get_congs : theory -> thm list
    31     val get_congs : theory -> thm list
    31 end
    32 end
    32 
    33 
    33 
    34 
    34 structure FundefPackage  =
    35 structure FundefPackage  =
   160 (* congruence rules *)
   161 (* congruence rules *)
   161 
   162 
   162 val cong_add = Thm.declaration_attribute (map_fundef_congs o Drule.add_rule o safe_mk_meta_eq);
   163 val cong_add = Thm.declaration_attribute (map_fundef_congs o Drule.add_rule o safe_mk_meta_eq);
   163 val cong_del = Thm.declaration_attribute (map_fundef_congs o Drule.del_rule o safe_mk_meta_eq);
   164 val cong_del = Thm.declaration_attribute (map_fundef_congs o Drule.del_rule o safe_mk_meta_eq);
   164 
   165 
       
   166 (* Datatype hook to declare datatype congs as "fundef_congs" *)
       
   167 
       
   168 
       
   169 fun add_case_cong n thy = 
       
   170     Context.theory_map (map_fundef_congs (Drule.add_rule 
       
   171                           (DatatypePackage.get_datatype thy n |> the
       
   172                            |> #case_cong
       
   173                            |> safe_mk_meta_eq))) 
       
   174                        thy
       
   175 
       
   176 val case_cong_hook = fold add_case_cong
       
   177 
       
   178 val setup_case_cong_hook = 
       
   179     DatatypeHooks.add case_cong_hook
       
   180     #> (fn thy => case_cong_hook (Symtab.keys (DatatypePackage.get_datatypes thy)) thy)
   165 
   181 
   166 (* setup *)
   182 (* setup *)
   167 
   183 
   168 val setup = FundefData.init #> FundefCongs.init
   184 val setup = 
   169         #>  Attrib.add_attributes
   185     FundefData.init 
   170                 [("fundef_cong", Attrib.add_del_args cong_add cong_del, "declaration of congruence rule for function definitions")]
   186       #> FundefCongs.init
   171 
   187       #>  Attrib.add_attributes
       
   188             [("fundef_cong", Attrib.add_del_args cong_add cong_del, "declaration of congruence rule for function definitions")]
       
   189       #> setup_case_cong_hook
   172 
   190 
   173 val get_congs = FundefCommon.get_fundef_congs o Context.Theory
   191 val get_congs = FundefCommon.get_fundef_congs o Context.Theory
       
   192 
   174 
   193 
   175 
   194 
   176 (* outer syntax *)
   195 (* outer syntax *)
   177 
   196 
   178 local structure P = OuterParse and K = OuterKeyword in
   197 local structure P = OuterParse and K = OuterKeyword in