Skip to content

Bad code generated for zip/filter/filter loop

Here is the program:

zip_filter :: (Num a, Ord a) => a -> [a] -> [a] -> [a]
zip_filter x as bs = zipWith (+) (filter (<x) as) (filter (<x) bs)

GHC generates this:

poly_z_smp = \ (@ a_aiz) _ -> GHC.Types.[] @ a_aiz

T.zip_filter =
  \ (@ a_aiz) $dNum_ajm $dOrd_ajn eta_B3 eta_B2 eta_B1 ->
    letrec {
      go_smr :: [a_aiz] -> [a_aiz] -> [a_aiz]
      go_smr =
        \ (ds_ak5 :: [a_aiz]) ->
          case ds_ak5 of _ {
            [] -> poly_z_smp @ a_aiz;
            : y_aka ys_akb ->
              let {
                r_smt :: [a_aiz] -> [a_aiz]
                r_smt = go_smr ys_akb } in
              case GHC.Classes.< @ a_aiz $dOrd_ajn y_aka eta_B3 of _ {
                GHC.Bool.False -> r_smt;
                GHC.Bool.True ->
                  \ (ds_alR :: [a_aiz]) ->
                    case ds_alR of _ {
                      [] -> GHC.Types.[] @ a_aiz;
                      : y_alW ys_alX ->
                        GHC.Types.:
                          @ a_aiz (GHC.Num.+ @ a_aiz $dNum_ajm y_aka y_alW) (r_smt ys_alX)
                    }
              }
          }; } in
    go_smr
      eta_B2
      (GHC.List.filter
         @ a_aiz
         (\ (ds_djz :: a_aiz) ->
            GHC.Classes.< @ a_aiz $dOrd_ajn ds_djz eta_B3)
         eta_B1)

Eta-expanding go_smr would result in much better code.

Trac metadata
Trac field Value
Version 6.13
Type Bug
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Compiler
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information