src/HOL/Nominal/nominal_package.ML
changeset 31458 b1cf26f2919b
parent 30450 7655e6533209
child 31671 81e5e8ffe92f
equal deleted inserted replaced
31457:d1cb222438d8 31458:b1cf26f2919b
   730     (** strips the "_Rep" in type names *)
   730     (** strips the "_Rep" in type names *)
   731     fun strip_nth_name i s =
   731     fun strip_nth_name i s =
   732       let val xs = Long_Name.explode s;
   732       let val xs = Long_Name.explode s;
   733       in Long_Name.implode (Library.nth_map (length xs - i) (strip_suffix 4) xs) end;
   733       in Long_Name.implode (Library.nth_map (length xs - i) (strip_suffix 4) xs) end;
   734 
   734 
   735     val (descr'', ndescr) = ListPair.unzip (List.mapPartial
   735     val (descr'', ndescr) = ListPair.unzip (map_filter
   736       (fn (i, ("Nominal.noption", _, _)) => NONE
   736       (fn (i, ("Nominal.noption", _, _)) => NONE
   737         | (i, (s, dts, constrs)) =>
   737         | (i, (s, dts, constrs)) =>
   738              let
   738              let
   739                val SOME index = AList.lookup op = ty_idxs i;
   739                val SOME index = AList.lookup op = ty_idxs i;
   740                val (constrs1, constrs2) = ListPair.unzip
   740                val (constrs2, constrs1) =
   741                  (map (fn (cname, cargs) => apfst (pair (strip_nth_name 2 (strip_nth_name 1 cname)))
   741                  map_split (fn (cname, cargs) =>
   742                    (Library.foldl_map (fn (dts, dt) =>
   742                    apsnd (pair (strip_nth_name 2 (strip_nth_name 1 cname)))
       
   743                    (fold_map (fn dt => fn dts =>
   743                      let val (dts', dt') = strip_option dt
   744                      let val (dts', dt') = strip_option dt
   744                      in (dts @ dts' @ [reindex dt'], (length dts, length dts')) end)
   745                      in ((length dts, length dts'), dts @ dts' @ [reindex dt']) end)
   745                        ([], cargs))) constrs)
   746                        cargs [])) constrs
   746              in SOME ((index, (strip_nth_name 1 s,  map reindex dts, constrs1)),
   747              in SOME ((index, (strip_nth_name 1 s,  map reindex dts, constrs1)),
   747                (index, constrs2))
   748                (index, constrs2))
   748              end) descr);
   749              end) descr);
   749 
   750 
   750     val (descr1, descr2) = chop (length new_type_names) descr'';
   751     val (descr1, descr2) = chop (length new_type_names) descr'';