src/HOL/Codatatype/Tools/bnf_fp_sugar.ML
changeset 49392 e1f325ab9503
parent 49389 da621dc65146
child 49393 21f62b300d08
equal deleted inserted replaced
49391:3a96797fd53e 49392:e1f325ab9503
    36 
    36 
    37 fun split_list10 xs =
    37 fun split_list10 xs =
    38   (map #1 xs, map #2 xs, map #3 xs, map #4 xs, map #5 xs, map #6 xs, map #7 xs, map #8 xs,
    38   (map #1 xs, map #2 xs, map #3 xs, map #4 xs, map #5 xs, map #6 xs, map #7 xs, map #8 xs,
    39    map #9 xs, map #10 xs);
    39    map #9 xs, map #10 xs);
    40 
    40 
    41 fun strip_map_type @{type_name fun} (Type (_, [T, Type (_, [T', T''])])) = ([T, T'], T'')
       
    42   | strip_map_type _ T = strip_type T;
       
    43 
       
    44 fun resort_tfree S (TFree (s, _)) = TFree (s, S);
    41 fun resort_tfree S (TFree (s, _)) = TFree (s, S);
    45 
    42 
    46 fun typ_subst inst (T as Type (s, Ts)) =
    43 fun typ_subst inst (T as Type (s, Ts)) =
    47     (case AList.lookup (op =) inst T of
    44     (case AList.lookup (op =) inst T of
    48       NONE => Type (s, map (typ_subst inst) Ts)
    45       NONE => Type (s, map (typ_subst inst) Ts)
   499     val pre_map_defs = map map_def_of_bnf pre_bnfs;
   496     val pre_map_defs = map map_def_of_bnf pre_bnfs;
   500     val pre_set_defss = map set_defs_of_bnf pre_bnfs;
   497     val pre_set_defss = map set_defs_of_bnf pre_bnfs;
   501     val nested_set_natural's = maps set_natural'_of_bnf nested_bnfs;
   498     val nested_set_natural's = maps set_natural'_of_bnf nested_bnfs;
   502     val nesting_map_ids = map map_id_of_bnf nesting_bnfs;
   499     val nesting_map_ids = map map_id_of_bnf nesting_bnfs;
   503 
   500 
   504     fun mk_map s Ts Us t =
   501     fun mk_map live' Ts Us t =
   505       let val (Type (_, Ts0), Type (_, Us0)) = strip_map_type s (fastype_of t) |>> List.last in
   502       let val (Type (_, Ts0), Type (_, Us0)) = strip_typeN live' (fastype_of t) |>> List.last in
   506         Term.subst_atomic_types (Ts0 @ Us0 ~~ Ts @ Us) t
   503         Term.subst_atomic_types (Ts0 @ Us0 ~~ Ts @ Us) t
   507       end;
   504       end;
   508 
   505 
   509     fun build_map build_arg (T as Type (s, Ts)) (U as Type (_, Us)) =
   506     fun build_map build_arg (T as Type (s, Ts)) (U as Type (_, Us)) =
   510       let
   507       let
   511         val map0 = map_of_bnf (the (bnf_of lthy s));
   508         val bnf = the (bnf_of lthy s);
   512         val mapx = mk_map s Ts Us map0;
   509         val live' = live_of_bnf bnf + 1;
   513         val TUs = map dest_funT (fst (split_last (fst (strip_map_type s (fastype_of mapx)))));
   510         val mapx = mk_map live' Ts Us (map_of_bnf bnf);
       
   511         val TUs = map dest_funT (fst (split_last (fst (strip_typeN live' (fastype_of mapx)))));
   514         val args = map build_arg TUs;
   512         val args = map build_arg TUs;
   515       in Term.list_comb (mapx, args) end;
   513       in Term.list_comb (mapx, args) end;
   516 
   514 
   517     fun derive_induct_iter_rec_thms_for_types ((ctrss, _, iters, recs, xsss, ctr_defss, _, _,
   515     fun derive_induct_iter_rec_thms_for_types ((ctrss, _, iters, recs, xsss, ctr_defss, _, _,
   518         iter_defs, rec_defs), lthy) =
   516         iter_defs, rec_defs), lthy) =