src/HOL/Codatatype/Tools/bnf_fp_sugar.ML
changeset 50351 a2e6473145e4
parent 50345 276ff43ee0b1
child 50352 538687a77075
     1.1 --- a/src/HOL/Codatatype/Tools/bnf_fp_sugar.ML	Wed Sep 12 17:26:05 2012 +0200
     1.2 +++ b/src/HOL/Codatatype/Tools/bnf_fp_sugar.ML	Wed Sep 12 17:26:05 2012 +0200
     1.3 @@ -83,7 +83,7 @@
     1.4    if length As = length As' then map2 merge_type_arg As As' else cannot_merge_types ();
     1.5  
     1.6  fun type_args_constrained_of (((cAs, _), _), _) = cAs;
     1.7 -fun type_binder_of (((_, b), _), _) = b;
     1.8 +fun type_binding_of (((_, b), _), _) = b;
     1.9  fun mixfix_of ((_, mx), _) = mx;
    1.10  fun ctr_specs_of (_, ctr_specs) = ctr_specs;
    1.11  
    1.12 @@ -123,14 +123,14 @@
    1.13        locale and shadows an existing global type*)
    1.14      val fake_thy =
    1.15        Theory.copy #> fold (fn spec => perhaps (try (Sign.add_type no_defs_lthy
    1.16 -        (type_binder_of spec, length (type_args_constrained_of spec), mixfix_of spec)))) specs;
    1.17 +        (type_binding_of spec, length (type_args_constrained_of spec), mixfix_of spec)))) specs;
    1.18      val fake_lthy = Proof_Context.background_theory fake_thy no_defs_lthy;
    1.19  
    1.20      fun mk_fake_T b =
    1.21        Type (fst (Term.dest_Type (Proof_Context.read_type_name fake_lthy true (Binding.name_of b))),
    1.22          unsorted_As);
    1.23  
    1.24 -    val fp_bs = map type_binder_of specs;
    1.25 +    val fp_bs = map type_binding_of specs;
    1.26      val fake_Ts = map mk_fake_T fp_bs;
    1.27  
    1.28      val mixfixes = map mixfix_of specs;
    1.29 @@ -140,14 +140,14 @@
    1.30  
    1.31      val ctr_specss = map ctr_specs_of specs;
    1.32  
    1.33 -    val disc_binderss = map (map disc_of) ctr_specss;
    1.34 -    val ctr_binderss =
    1.35 +    val disc_bindingss = map (map disc_of) ctr_specss;
    1.36 +    val ctr_bindingss =
    1.37        map2 (fn fp_b => map (Binding.qualify false (Binding.name_of fp_b) o ctr_of))
    1.38          fp_bs ctr_specss;
    1.39      val ctr_argsss = map (map args_of) ctr_specss;
    1.40      val ctr_mixfixess = map (map ctr_mixfix_of) ctr_specss;
    1.41  
    1.42 -    val sel_bindersss = map (map (map fst)) ctr_argsss;
    1.43 +    val sel_bindingsss = map (map (map fst)) ctr_argsss;
    1.44      val fake_ctr_Tsss0 = map (map (map (prepare_typ fake_lthy o snd))) ctr_argsss;
    1.45      val raw_sel_defaultsss = map (map defaults_of) ctr_specss;
    1.46  
    1.47 @@ -218,8 +218,8 @@
    1.48  
    1.49      fun mk_iter_like Ts Us t =
    1.50        let
    1.51 -        val (binders, body) = strip_type (fastype_of t);
    1.52 -        val (f_Us, prebody) = split_last binders;
    1.53 +        val (bindings, body) = strip_type (fastype_of t);
    1.54 +        val (f_Us, prebody) = split_last bindings;
    1.55          val Type (_, Ts0) = if lfp then prebody else body;
    1.56          val Us0 = distinct (op =) (map (if lfp then body_type else domain_type) f_Us);
    1.57        in
    1.58 @@ -334,8 +334,8 @@
    1.59          end;
    1.60  
    1.61      fun define_ctrs_case_for_type ((((((((((((((((((fp_b, fpT), C), fld), unf), fp_iter), fp_rec),
    1.62 -          fld_unf), unf_fld), fld_inject), n), ks), ms), ctr_binders), ctr_mixfixes), ctr_Tss),
    1.63 -        disc_binders), sel_binderss), raw_sel_defaultss) no_defs_lthy =
    1.64 +          fld_unf), unf_fld), fld_inject), n), ks), ms), ctr_bindings), ctr_mixfixes), ctr_Tss),
    1.65 +        disc_bindings), sel_bindingss), raw_sel_defaultss) no_defs_lthy =
    1.66        let
    1.67          val unfT = domain_type (fastype_of fld);
    1.68          val ctr_prod_Ts = map HOLogic.mk_tupleT ctr_Tss;
    1.69 @@ -353,7 +353,7 @@
    1.70            map2 (fn k => fn xs => fold_rev Term.lambda xs (fld $
    1.71              mk_InN_balanced ctr_sum_prod_T n (HOLogic.mk_tuple xs) k)) ks xss;
    1.72  
    1.73 -        val case_binder = Binding.suffix_name ("_" ^ caseN) fp_b;
    1.74 +        val case_binding = Binding.suffix_name ("_" ^ caseN) fp_b;
    1.75  
    1.76          val case_rhs =
    1.77            fold_rev Term.lambda (fs @ [v])
    1.78 @@ -362,7 +362,7 @@
    1.79          val ((raw_case :: raw_ctrs, raw_case_def :: raw_ctr_defs), (lthy', lthy)) = no_defs_lthy
    1.80            |> apfst split_list o fold_map3 (fn b => fn mx => fn rhs =>
    1.81                Local_Theory.define ((b, mx), ((Thm.def_binding b, []), rhs)) #>> apsnd snd)
    1.82 -            (case_binder :: ctr_binders) (NoSyn :: ctr_mixfixes) (case_rhs :: ctr_rhss)
    1.83 +            (case_binding :: ctr_bindings) (NoSyn :: ctr_mixfixes) (case_rhs :: ctr_rhss)
    1.84            ||> `Local_Theory.restore;
    1.85  
    1.86          val phi = Proof_Context.export_morphism lthy lthy';
    1.87 @@ -420,25 +420,23 @@
    1.88              fun generate_iter_like (suf, fp_iter_like, (fss, f_Tss, xssss)) =
    1.89                let
    1.90                  val res_T = fold_rev (curry (op --->)) f_Tss fpT_to_C;
    1.91 -
    1.92 -                val binder = Binding.suffix_name ("_" ^ suf) fp_b;
    1.93 -
    1.94 +                val binding = Binding.suffix_name ("_" ^ suf) fp_b;
    1.95                  val spec =
    1.96 -                  mk_Trueprop_eq (lists_bmoc fss (Free (Binding.name_of binder, res_T)),
    1.97 +                  mk_Trueprop_eq (lists_bmoc fss (Free (Binding.name_of binding, res_T)),
    1.98                      Term.list_comb (fp_iter_like,
    1.99                        map2 (mk_sum_caseN_balanced oo map2 mk_uncurried2_fun) fss xssss));
   1.100 -              in (binder, spec) end;
   1.101 +              in (binding, spec) end;
   1.102  
   1.103              val iter_like_infos =
   1.104                [(iterN, fp_iter, iter_only),
   1.105                 (recN, fp_rec, rec_only)];
   1.106  
   1.107 -            val (binders, specs) = map generate_iter_like iter_like_infos |> split_list;
   1.108 +            val (bindings, specs) = map generate_iter_like iter_like_infos |> split_list;
   1.109  
   1.110              val ((csts, defs), (lthy', lthy)) = no_defs_lthy
   1.111                |> apfst split_list o fold_map2 (fn b => fn spec =>
   1.112                  Specification.definition (SOME (b, NONE, NoSyn), ((Thm.def_binding b, []), spec))
   1.113 -                #>> apsnd snd) binders specs
   1.114 +                #>> apsnd snd) bindings specs
   1.115                ||> `Local_Theory.restore;
   1.116  
   1.117              val phi = Proof_Context.export_morphism lthy lthy';
   1.118 @@ -463,25 +461,23 @@
   1.119                  pf_Tss))) =
   1.120                let
   1.121                  val res_T = fold_rev (curry (op --->)) pf_Tss B_to_fpT;
   1.122 -
   1.123 -                val binder = Binding.suffix_name ("_" ^ suf) fp_b;
   1.124 -
   1.125 +                val binding = Binding.suffix_name ("_" ^ suf) fp_b;
   1.126                  val spec =
   1.127 -                  mk_Trueprop_eq (lists_bmoc pfss (Free (Binding.name_of binder, res_T)),
   1.128 +                  mk_Trueprop_eq (lists_bmoc pfss (Free (Binding.name_of binding, res_T)),
   1.129                      Term.list_comb (fp_iter_like,
   1.130                        map5 mk_preds_getterss_join cs ns cpss f_sum_prod_Ts cqfsss));
   1.131 -              in (binder, spec) end;
   1.132 +              in (binding, spec) end;
   1.133  
   1.134              val coiter_like_infos =
   1.135                [(coiterN, fp_iter, coiter_only),
   1.136                 (corecN, fp_rec, corec_only)];
   1.137  
   1.138 -            val (binders, specs) = map generate_coiter_like coiter_like_infos |> split_list;
   1.139 +            val (bindings, specs) = map generate_coiter_like coiter_like_infos |> split_list;
   1.140  
   1.141              val ((csts, defs), (lthy', lthy)) = no_defs_lthy
   1.142                |> apfst split_list o fold_map2 (fn b => fn spec =>
   1.143                  Specification.definition (SOME (b, NONE, NoSyn), ((Thm.def_binding b, []), spec))
   1.144 -                #>> apsnd snd) binders specs
   1.145 +                #>> apsnd snd) bindings specs
   1.146                ||> `Local_Theory.restore;
   1.147  
   1.148              val phi = Proof_Context.export_morphism lthy lthy';
   1.149 @@ -496,7 +492,7 @@
   1.150  
   1.151          fun wrap lthy =
   1.152            let val sel_defaultss = map (map (apsnd (prepare_term lthy))) raw_sel_defaultss in
   1.153 -            wrap_datatype tacss (((no_dests, ctrs0), casex0), (disc_binders, (sel_binderss,
   1.154 +            wrap_datatype tacss (((no_dests, ctrs0), casex0), (disc_bindings, (sel_bindingss,
   1.155                sel_defaultss))) lthy
   1.156            end;
   1.157  
   1.158 @@ -685,8 +681,8 @@
   1.159  
   1.160      val lthy' = lthy
   1.161        |> fold_map define_ctrs_case_for_type (fp_bs ~~ fpTs ~~ Cs ~~ flds ~~ unfs ~~ fp_iters ~~
   1.162 -        fp_recs ~~ fld_unfs ~~ unf_flds ~~ fld_injects ~~ ns ~~ kss ~~ mss ~~ ctr_binderss ~~
   1.163 -        ctr_mixfixess ~~ ctr_Tsss ~~ disc_binderss ~~ sel_bindersss ~~ raw_sel_defaultsss)
   1.164 +        fp_recs ~~ fld_unfs ~~ unf_flds ~~ fld_injects ~~ ns ~~ kss ~~ mss ~~ ctr_bindingss ~~
   1.165 +        ctr_mixfixess ~~ ctr_Tsss ~~ disc_bindingss ~~ sel_bindingsss ~~ raw_sel_defaultsss)
   1.166        |>> split_list |> wrap_types_and_define_iter_likes
   1.167        |> (if lfp then derive_iter_rec_thms_for_types else derive_coiter_corec_thms_for_types);
   1.168  
   1.169 @@ -701,11 +697,11 @@
   1.170  val datatype_cmd = define_datatype Typedecl.read_constraint Syntax.parse_typ Syntax.read_term;
   1.171  
   1.172  val parse_binding_colon = Parse.binding --| @{keyword ":"};
   1.173 -val parse_opt_binding_colon = Scan.optional parse_binding_colon no_binder;
   1.174 +val parse_opt_binding_colon = Scan.optional parse_binding_colon no_binding;
   1.175  
   1.176  val parse_ctr_arg =
   1.177    @{keyword "("} |-- parse_binding_colon -- Parse.typ --| @{keyword ")"} ||
   1.178 -  (Parse.typ >> pair no_binder);
   1.179 +  (Parse.typ >> pair no_binding);
   1.180  
   1.181  val parse_defaults =
   1.182    @{keyword "("} |-- @{keyword "defaults"} |-- Scan.repeat parse_bound_term --| @{keyword ")"};