In short, typeclass is just like interface, so it's not so hard to understand.
Let's see some code about Maybe functor, functor has a special map function:
class Functor Maybe where
fmap :: (a -> b) -> Maybe a -> Maybe b
instance Functor Maybe where
fmap func (Just x) = Just (func x)
fmap func Nothing = Nothing
Functor is a typeclass.
Applicative Functor extends Functor.
Monad extends Applicative.
class Applicative m => Monad m where
return :: a -> m a
(>>=) :: m a -> (a -> m b) -> m b
And another one Monoid is a math concept. It's a typeclass too.
They are all typeclasses.
Top comments (1)
Just a small side note, in the class declaration you don't specify a concrete type: