src/HOL/Tools/function_package/fundef_datatype.ML
changeset 20999 9131d8e96dba
parent 20875 95d24e8d117e
child 21051 c49467a9c1e1
equal deleted inserted replaced
20998:714a08286899 20999:9131d8e96dba
    11     val pat_complete_tac: int -> tactic
    11     val pat_complete_tac: int -> tactic
    12 
    12 
    13     val pat_completeness : method
    13     val pat_completeness : method
    14     val setup : theory -> theory
    14     val setup : theory -> theory
    15 end
    15 end
    16 
       
    17 
       
    18 
    16 
    19 structure FundefDatatype : FUNDEF_DATATYPE =
    17 structure FundefDatatype : FUNDEF_DATATYPE =
    20 struct
    18 struct
    21 
    19 
    22 
    20 
   165 
   163 
   166 val by_pat_completeness_simp =
   164 val by_pat_completeness_simp =
   167     Proof.global_terminal_proof
   165     Proof.global_terminal_proof
   168       (Method.Basic (K pat_completeness),
   166       (Method.Basic (K pat_completeness),
   169        SOME (Method.Source (Args.src (("simp_all", []), Position.none))))
   167        SOME (Method.Source (Args.src (("simp_all", []), Position.none))))
       
   168          (* FIXME avoid dynamic scoping of method name! *)
   170 
   169 
   171 
   170 
   172 val setup =
   171 val setup =
   173     Method.add_methods [("pat_completeness", Method.no_args pat_completeness, "Completeness prover for datatype patterns")]
   172     Method.add_methods [("pat_completeness", Method.no_args pat_completeness, "Completeness prover for datatype patterns")]
   174 
   173 
   175 
   174 
   176 
   175 
   177 
   176 
   178 
       
   179 
       
   180 local structure P = OuterParse and K = OuterKeyword in
   177 local structure P = OuterParse and K = OuterKeyword in
   181 
   178 
   182 
       
   183 fun local_theory_to_proof f = 
       
   184     Toplevel.theory_to_proof (f o TheoryTarget.init NONE)
       
   185 
   179 
   186 fun or_list1 s = P.enum1 "|" s
   180 fun or_list1 s = P.enum1 "|" s
   187 val otherwise = P.$$$ "(" |-- P.$$$ "otherwise" --| P.$$$ ")"
   181 val otherwise = P.$$$ "(" |-- P.$$$ "otherwise" --| P.$$$ ")"
   188 val statement_ow = P.and_list1 (P.opt_thm_name ":" -- Scan.repeat1 (P.prop -- Scan.optional (otherwise >> K true) false))
   182 val statement_ow = P.and_list1 (P.opt_thm_name ":" -- Scan.repeat1 (P.prop -- Scan.optional (otherwise >> K true) false))
   189 val statements_ow = or_list1 statement_ow
   183 val statements_ow = or_list1 statement_ow
   190 
   184 
   191 val funP =
   185 val funP =
   192   OuterSyntax.command "fun" "define general recursive functions (short version)" K.thy_decl
   186   OuterSyntax.command "fun" "define general recursive functions (short version)" K.thy_decl
   193   ((P.opt_locale_target -- P.fixes --| P.$$$ "where" -- statements_ow)
   187   ((P.opt_locale_target -- P.fixes --| P.$$$ "where" -- statements_ow)
   194      >> (fn ((target, fixes), statements) =>
   188      >> (fn ((target, fixes), statements) =>
   195             Toplevel.print o Toplevel.local_theory NONE (FundefPackage.add_fundef fixes statements FundefCommon.fun_config 
   189             Toplevel.print o
   196                                                                                   #> by_pat_completeness_simp)));
   190             Toplevel.local_theory target
       
   191               (FundefPackage.add_fundef fixes statements FundefCommon.fun_config
       
   192                #> by_pat_completeness_simp)));
   197 
   193 
   198 val _ = OuterSyntax.add_parsers [funP];
   194 val _ = OuterSyntax.add_parsers [funP];
   199 end
   195 end
   200 
   196 
   201 
       
   202 
       
   203 
       
   204 
       
   205 
       
   206 
       
   207 
       
   208 end
   197 end