Using WrappedApplicative with DerivingVia
Topsii opened this issue · comments
Topsii commented
Wouldn't it make sense to define WrappedApplicative
's fmap
via liftA
instead of <$>
to support the following use case?
{-# language DerivingVia #-}
import Data.Functor.Apply
data Vec3 a = MkVec3 a a a
deriving stock Show
deriving Functor via WrappedApplicative Vec3
instance Applicative Vec3 where
pure x = MkVec3 x x x
(MkVec3 f g h) <*> (MkVec3 x y z) = MkVec3 (f x) (g y) (h z)
This would be a breaking change since the instance would change from
instance Functor f => Functor (WrappedApplicative f) where
fmap f (WrapApplicative a) = WrapApplicative (f <$> a)
to
instance Applicative f => Functor (WrappedApplicative f) where
fmap f (WrapApplicative a) = WrapApplicative (liftA f a)
However due to the name WrappedApplicative
it seems reasonable to require an Applicative
instance.
Topsii commented
The same approach does not work for WrappedMonad
. Notably it is in conflict with the Monad
of no return
proposal.