-
Notifications
You must be signed in to change notification settings - Fork 18
Description
(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:
- https://gitlab.haskell.org/ghc/ghc/-/issues/13191, referenced in https://hackage.haskell.org/package/base-4.10.0.0/changelog
- MR https://gitlab.haskell.org/ghc/ghc/-/merge_requests/6468 (Note: this one is on
liftA2
andjoin
)