[Haskell-cafe] Re: Applicative but not Monad

Heinrich Apfelmus apfelmus at quantentunnel.de
Sat Oct 31 06:22:59 EDT 2009

Dan Weston wrote:
> Can you elaborate on why Const is not a monad?
> return x = Const x
> fmap f (Const x) = Const (f x)
> join (Const (Const x)) = Const x

This is not  Const , this is the  Identity  monad.

The real  Const  looks like this:

   newtype Const b a = Const b

   instance Monoid b => Applicative (Const b) where
        pure x = Const mempty
        (Const b) <*> (Const b') = Const (b `mappend` b')

The only possible monad instance would be

   return x = Const mempty
   fmap f (Const b) = Const b
   join (Const b)   = Const b

but that's not just  ()  turned into a monad.



More information about the Haskell-Cafe mailing list