src/HOL/Tools/Ctr_Sugar/case_translation.ML
changeset 61004 1dd6669ff612
parent 60924 610794dff23c
child 64961 d19a5579ffb8
equal deleted inserted replaced
60993:531a48ae1425 61004:1dd6669ff612
   468 fun dest_case ctxt d used t =
   468 fun dest_case ctxt d used t =
   469   (case apfst name_of (strip_comb t) of
   469   (case apfst name_of (strip_comb t) of
   470     (SOME cname, ts as _ :: _) =>
   470     (SOME cname, ts as _ :: _) =>
   471       let
   471       let
   472         val (fs, x) = split_last ts;
   472         val (fs, x) = split_last ts;
   473         fun strip_abs i Us t =
   473         fun strip_abs i t =
   474           let
   474           let
   475             val zs = strip_abs_vars t;
   475             val zs = strip_abs_vars t;
   476             val j = length zs;
   476             val j = length zs;
   477             val (xs, ys) =
   477             val (xs, ys) =
   478               if j < i then (zs @ map (pair "x") (drop j Us), [])
   478               if j < i then (zs @
       
   479                 map (pair "x") (drop j (take i (binder_types (fastype_of t)))), [])
   479               else chop i zs;
   480               else chop i zs;
   480             val u = fold_rev Term.abs ys (strip_abs_body t);
   481             val u = fold_rev Term.abs ys (strip_abs_body t);
   481             val xs' = map Free
   482             val xs' = map Free
   482               ((fold_map Name.variant (map fst xs)
   483               ((fold_map Name.variant (map fst xs)
   483                   (Term.declare_term_names u used) |> fst) ~~
   484                   (Term.declare_term_names u used) |> fst) ~~
   499               let
   500               let
   500                 val cases = map (fn (Const (s, U), t) =>
   501                 val cases = map (fn (Const (s, U), t) =>
   501                   let
   502                   let
   502                     val Us = binder_types U;
   503                     val Us = binder_types U;
   503                     val k = length Us;
   504                     val k = length Us;
   504                     val p as (xs, _) = strip_abs k Us t;
   505                     val p as (xs, _) = strip_abs k t;
   505                   in
   506                   in
   506                     (Const (s, map fastype_of xs ---> fastype_of x), p, is_dependent k t)
   507                     (Const (s, map fastype_of xs ---> fastype_of x), p, is_dependent k t)
   507                   end) (constructors ~~ fs);
   508                   end) (constructors ~~ fs);
   508                 val cases' =
   509                 val cases' =
   509                   sort (int_ord o swap o apply2 (length o snd))
   510                   sort (int_ord o swap o apply2 (length o snd))