Skip to content

Default definition of liftA2 is not eta-expanded

The default definition for liftA2 is like this:

    liftA2 :: (a -> b -> c) -> f a -> f b -> f c
    liftA2 f x = (<*>) (fmap f x)

The eta-reduced form leads to suboptimal code (here for Tainted from !5583 (closed)):

GHC.Data.Tainted.$fApplicativeTainted_$cliftA2
  = \ (@a_a26x)
      (@b_a26y)
      (@c_a26z)
      (eta_a3NY :: a_a26x -> b_a26y -> c_a26z)
      (eta1_a3NZ :: Tainted a_a26x) ->
      let {
        tf_s43V [Dmd=LP(L,L)] :: Tainted (b_a26y -> c_a26z)
        [LclId]
        tf_s43V
          = case eta1_a3NZ of { Tainted_ ds_d3Mg a1_a1Pg ->
            case ds_d3Mg of {
              False ->
                GHC.Data.Tainted.Tainted_
                  @(b_a26y -> c_a26z) ghc-prim:GHC.Types.False (eta_a3NY a1_a1Pg);
              True ->
                case eta_a3NY a1_a1Pg of a2_X0 { __DEFAULT ->
                GHC.Data.Tainted.Tainted_
                  @(b_a26y -> c_a26z) ghc-prim:GHC.Types.True a2_X0
                }
            }
            } } in
      \ (ta_a1OI :: Tainted b_a26y) ->
        case tf_s43V of { Tainted_ ds_d3ID a1_a1Pi ->
        case ds_d3ID of {
          False ->
            case ta_a1OI of { Tainted_ ds1_X4 a2_X5 ->
            case ds1_X4 of {
              False ->
                GHC.Data.Tainted.Tainted_
                  @c_a26z ghc-prim:GHC.Types.False (a1_a1Pi a2_X5);
              True ->
                case a1_a1Pi a2_X5 of a3_X0 { __DEFAULT ->
                GHC.Data.Tainted.Tainted_ @c_a26z ghc-prim:GHC.Types.True a3_X0
                }
            }
            };
          True ->
            case ta_a1OI of { Tainted_ ipv_s40O ipv1_s40P ->
            case a1_a1Pi ipv1_s40P of a2_X3 { __DEFAULT ->
            GHC.Data.Tainted.Tainted_ @c_a26z ghc-prim:GHC.Types.True a2_X3
            }
            }
        }
        }

It's probably enough to simply eta-expand liftA2s defn. By definition, this also affects (*>).

Edited by Sebastian Graf
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information