Skip to content

Export liftA2 from Prelude #50

@andreasabel

Description

@andreasabel

(Transfered from https://gitlab.haskell.org/ghc/ghc/-/issues/20945):
As alternative to <*> method liftA2 can be used to instantiate Applicative, but only the former is exported from Prelude. I propose to also export the latter, for reasons of symmetry and clarity of error messages.

Detailed, anecdotic motivation: Consider:

{-# LANGUAGE DeriveFunctor #-}

data Foo a = Foo a deriving (Functor)

instance Applicative (Foo) where
  pure = Foo

Since base shipped with GHC 8.2, this gives the following warning:

warning: [-Wmissing-methods]
    • No explicit implementation for
        either ‘<*>’ or ‘GHC.Base.liftA2’
    • In the instance declaration for ‘Applicative Foo’

Trying to follow up on this literally,

instance Applicative Foo where
  pure = Foo
  GHC.Base.liftA2 f (Foo a) (Foo b) = Foo $ f a b

I get other errors:

    ‘GHC.Base.liftA2’ is not a (visible) method of class ‘Applicative’
   |
10 |   GHC.Base.liftA2 f (Foo a) (Foo b) = Foo $ f a b
   |   ^^^^^^^^^^^^^^^

    Qualified name in binding position: GHC.Base.liftA2
   |
10 |   GHC.Base.liftA2 f (Foo a) (Foo b) = Foo $ f a b
   |   ^^^^^^^^^^^^^^^

GHC is giving me contradictory information here.
The workaround is import Control.Applicative, but it seems inconsistent that some methods of Applicative are exported by Prelude and some not, especially those that comprise a MINIMAL definition of an instance.

Proposal: export liftA2 also from Prelude.

Related, find some discussion there:

Metadata

Metadata

Assignees

No one assigned

    Labels

    approvedApproved by CLC votebase-4.18Implemented in base-4.18 (GHC 9.6)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions