
31 Oct
2009
31 Oct
'09
6:22 a.m.
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. Regards, apfelmus -- http://apfelmus.nfshost.com