class Functor f where
fmap :: (a -> b) -> f a -> fb
fmap id = id
fmap (f . g) F = fmap f (fmap g F) -- for any Functor F
class (Functor f) => Applicative f where
pure :: a -> f a
(<*>) :: f (a -> b) -> f a -> f b
(<$>) :: (Functor f) => (a -> b) -> f a -> f b
f <$> x = fmap f x
pure f <*> x = fmap f x
pure id <*> v = v
pure (.) <*> u <*> v <*> w = u <*> (v <*> w)
pure f <*> pure x = pure (f x)
u <*> pure y = pure ($ y) <*> u
class Monoid m where
mempty :: m
mappend :: m -> m -> m
mconcat :: [m] -> m
mconcat = foldr mappend mempty
mappend mempty x = x
mappend x mempty = x
mappend (mappend x y) z = mappend x (mappend y z)
class Monad m where
return :: a -> m a
(>>=) :: m a -> (a -> m b) -> m b
(>>) :: m a -> m b -> m b
x >> y = x >>= \_ -> y
fail :: String -> m a
fail msg = error msg
return x >>= f
is equivalent to
f x
m >>= return
is equivalent to
m
(m >>= f) >>= g
is equivalent to
m >>= (\x -> f x >>= g)