Questions about Functor, Applicative, Monad

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

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
написал(а): 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@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

Hi Corentin,
This may be a good answer for some of your questions:
http://stackoverflow.com/questions/7220436/good-examples-of-not-a-functor-fu...
Kenn
On Mon, May 5, 2014 at 6:31 PM, Corentin Dupont
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@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
participants (3)
-
Corentin Dupont
-
Kenn Knowles
-
MigMit