On Sat, Oct 31, 2009 at 6:22 AM, Heinrich Apfelmus <[email protected]> wrote: > 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.
This is inconsistent with the Applicative instance given above. Const a <*> Const b = Const (a `mappend` b) Const a `ap` Const b = Const a In other words, Const has at least two Applicative instances, one of which is not also a monad. -- Dave Menendez <[email protected]> <http://www.eyrie.org/~zednenem/> _______________________________________________ Haskell-Cafe mailing list [email protected] http://www.haskell.org/mailman/listinfo/haskell-cafe
