src/HOL/Tools/inductive_package.ML
changeset 26988 742e26213212
parent 26928 ca87aff1ad2d
child 27252 042aebff17e1
equal deleted inserted replaced
26987:978cefd606ad 26988:742e26213212
    73   val gen_add_inductive: add_ind_def ->
    73   val gen_add_inductive: add_ind_def ->
    74     bool -> bool -> (string * string option * mixfix) list ->
    74     bool -> bool -> (string * string option * mixfix) list ->
    75     (string * string option * mixfix) list ->
    75     (string * string option * mixfix) list ->
    76     ((bstring * Attrib.src list) * string) list -> (Facts.ref * Attrib.src list) list ->
    76     ((bstring * Attrib.src list) * string) list -> (Facts.ref * Attrib.src list) list ->
    77     local_theory -> inductive_result * local_theory
    77     local_theory -> inductive_result * local_theory
    78   val gen_ind_decl: add_ind_def ->
    78   val gen_ind_decl: add_ind_def -> bool ->
    79     bool -> OuterParse.token list ->
    79     OuterParse.token list -> (local_theory -> local_theory) * OuterParse.token list
    80     (Toplevel.transition -> Toplevel.transition) * OuterParse.token list
       
    81 end;
    80 end;
    82 
    81 
    83 structure InductivePackage: INDUCTIVE_PACKAGE =
    82 structure InductivePackage: INDUCTIVE_PACKAGE =
    84 struct
    83 struct
    85 
    84 
   943               else error ("Illegal nested case names " ^ quote (NameSpace.append a b))
   942               else error ("Illegal nested case names " ^ quote (NameSpace.append a b))
   944           | ((b, _), _) => error ("Illegal simultaneous specification " ^ quote b))
   943           | ((b, _), _) => error ("Illegal simultaneous specification " ^ quote b))
   945     | (a, _) => error ("Illegal local specification parameters for " ^ quote a));
   944     | (a, _) => error ("Illegal local specification parameters for " ^ quote a));
   946 
   945 
   947 fun gen_ind_decl mk_def coind =
   946 fun gen_ind_decl mk_def coind =
   948   P.opt_target --
       
   949   P.fixes -- P.for_fixes --
   947   P.fixes -- P.for_fixes --
   950   Scan.optional (P.$$$ "where" |-- P.!!! SpecParse.specification) [] --
   948   Scan.optional (P.$$$ "where" |-- P.!!! SpecParse.specification) [] --
   951   Scan.optional (P.$$$ "monos" |-- P.!!! SpecParse.xthms1) []
   949   Scan.optional (P.$$$ "monos" |-- P.!!! SpecParse.xthms1) []
   952   >> (fn ((((loc, preds), params), specs), monos) =>
   950   >> (fn (((preds, params), specs), monos) =>
   953     Toplevel.local_theory loc
   951       (snd o gen_add_inductive mk_def true coind preds params (flatten_specification specs) monos));
   954       (fn lthy => lthy |> gen_add_inductive mk_def true coind preds params
       
   955          (flatten_specification specs) monos |> snd));
       
   956 
   952 
   957 val ind_decl = gen_ind_decl add_ind_def;
   953 val ind_decl = gen_ind_decl add_ind_def;
   958 
   954 
   959 val _ = OuterSyntax.command "inductive" "define inductive predicates" K.thy_decl (ind_decl false);
   955 val _ = OuterSyntax.local_theory "inductive" "define inductive predicates" K.thy_decl (ind_decl false);
   960 val _ = OuterSyntax.command "coinductive" "define coinductive predicates" K.thy_decl (ind_decl true);
   956 val _ = OuterSyntax.local_theory "coinductive" "define coinductive predicates" K.thy_decl (ind_decl true);
   961 
   957 
   962 val _ =
   958 val _ =
   963   OuterSyntax.command "inductive_cases"
   959   OuterSyntax.local_theory "inductive_cases"
   964     "create simplified instances of elimination rules (improper)" K.thy_script
   960     "create simplified instances of elimination rules (improper)" K.thy_script
   965     (P.opt_target -- P.and_list1 SpecParse.spec
   961     (P.and_list1 SpecParse.spec >> (fn specs => snd o inductive_cases specs));
   966       >> (fn (loc, specs) => Toplevel.local_theory loc (snd o inductive_cases specs)));
       
   967 
   962 
   968 end;
   963 end;
   969 
   964 
   970 end;
   965 end;