Why no `instance (Monoid a, Applicative f)=> Monoid (f a)` for IO?
Brandon Simmons
brandon.m.simmons at gmail.com
Mon Jul 14 22:55:57 UTC 2014
It seems to me that this should be true for all `f a` like:
instance (Monoid a, Applicative f)=> Monoid (f a) where
mappend = liftA2 mappend
mempty = pure mempty
But I can't seem to find the particular `instance (Monoid a)=> Monoid
(IO a)` anywhere. Would that instance be incorrect, or does it live
somewhere else?
FWIW I noticed this when I started thinking about an instance I wanted
for 'contravariant':
instance (Monoid a, Applicative f)=> Monoid (Op (f a) b) where
mempty = Op $ const $ pure mempty
mappend (Op f) (Op g) = Op (\b-> liftA2 mappend (f b) (g b))
at which point I realized (I think) all `f a` are monoidal, and so we
ought to be able to get the instance above with just a deriving
Monoid.
Brandon
More information about the Glasgow-haskell-users
mailing list