I'm new to functional programming (coming from javascript), and I'm having a hard time telling the difference between the two, which is also messing with my understand of functors vs. monads.
Functor:
class Functor f where
fmap :: (a -> b) -> f a -> f b
Monad (simplified):
class Monad m where
(>>=) :: m a -> (a -> m b) -> m b
fmap
takes a function and a functor, and returns a functor.>>=
takes a function and a monad, and returns a monad.
The difference between the two is in the function parameter:
fmap
-(a -> b)
>>=
-(a -> m b)
>>=
takes a function parameter that returns a monad. I know that this is significant, but I'm having difficulty seeing how this one slight thing makes monads much more powerful than functors. Can someone explain?