[Haskell-cafe] Questions about Functor, Applicative, Monad

MigMit miguelimo38 at yandex.ru
Mon May 5 22:48:57 UTC 2014


newtype Const a b = Const a
instance Functor (Const a) where fmap _ (Const a) = Const a
pure :: b -> Const a b -- it's the same as just "b -> a"

instance Monoid a => Applicative (Const a) where
  pure _ = Const mempty
  Const a1 <*> Const a2 = Const (a1 `mappend` a2)

(>>=) :: Monoid a => Const a b -> (b -> Const a c) -> Const a c -- ?
-- it's isomorphic to just "a -> (b -> a) -> a"
-- note that "return b >>= h ~ h b", so, we need "bind :: a -> (b -> a) -> a" such that
-- bind mempty h = h b
-- whatever that "b" is.

Отправлено с iPad

> 06 мая 2014 г., в 2:31, Corentin Dupont <corentin.dupont at gmail.com> написал(а):
> 
> Hi everybody!
> Two questions in one:
> - When you define and instance of a Monad, why don't you get the Applicative and Functor instances for free? I seem that you can mechanically write them.
> - Do you have examples of things that are Functors but not Applicative? Applicative but not Monads?
> 
> Tchuss
> Corentin
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe


More information about the Haskell-Cafe mailing list