I am trying to define my own class of Functor
from this My code is:
class Functor f => Applicative f where
pure :: a -> f a
(<*>) :: liftA2 id
liftA2 :: (a -> b -> c) -> f a -> f b -> f c
liftA2 f x = (<*>) (fmap f x)
(*>) :: f a -> f b -> f b
a *> a2 = (id <$ a1) <*> a2
(<*) :: f a -> f b -> f a
(<*) = liftA2 const
I have hidden the functions from the Prelude
and GHC.Base
using:
import Prelude hiding (map, Maybe, Nothing, Just, (<*>))
import GHC.Base hiding (Functor, Maybe, Nothing, Just, map, (<*>), liftA2)
But I get the following error on the line (<*>) :: liftA2 id
:
Could not deduce (Main.Applicative f0)
from the context: Main.Applicative f
bound by the type signature for:
(<*>) :: forall (f :: * -> *) {k} (liftA2 :: k -> *) (id :: k).
Main.Applicative f =>
liftA2 id
I also get a similar error using (<*>)
in a1 *> a2 = (id <$ a1) <*> a2
Can anyone explain why this is happening?
Thanks,
Luke