Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using WrappedApplicative with DerivingVia #105

Open
Topsii opened this issue Jun 21, 2021 · 1 comment
Open

Using WrappedApplicative with DerivingVia #105

Topsii opened this issue Jun 21, 2021 · 1 comment

Comments

@Topsii
Copy link

Topsii commented Jun 21, 2021

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
Copy link
Author

Topsii commented Jun 21, 2021

The same approach does not work for WrappedMonad. Notably it is in conflict with the Monad of no return proposal.

https://gitlab.haskell.org/ghc/ghc/-/issues/13876

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant