Redefining applicative - Haskell

Welcome to the Functional Programming Zulip Chat Archive. You can join the chat here.

Asad Saeeduddin

I'm trying to do the following:

import qualified Prelude as P

class Functor f => Apply f
  zip :: f a -> f b -> f (a, b)

class Apply f => Applicative f
  pure:: a -> f a

instance Applicative f => P.Applicative f
  pure = pure
  f <*> x = uncurry ($) <$> zip f x
Asad Saeeduddin

But I get the following error:

src/Monoidal/Applicative.hs:19:10: error:
    • Could not deduce (Functor f)
        arising from the superclasses of an instance declaration
      from the context: Applicative f
        bound by the instance declaration
        at src/Monoidal/Applicative.hs:19:10-41
      Possible fix:
        add (Functor f) to the context of the instance declaration
    • In the instance declaration for ‘P.Applicative f’
19 | instance Applicative f => P.Applicative f
Asad Saeeduddin

shouldn't the Functor constraint on Apply make this work?


Interesting. Looks like a GHC bug.

Asad Saeeduddin

it works if I add Functor f to the constraints explicitly apparently

Asad Saeeduddin

like instance (Functor f, Applicative f) => P.Applicative f