Fwd: Semigroup and Monoid instances for ReaderT

On Tue, Mar 21, 2017 at 3:53 AM, Louis Pan
Hi all,
In my Glazier GUI library, I had to use newtype wrappers to create Semigroup and Monoid instances for ReaderT.
Is there a reason why ReaderT doesn't have an instance of Semigroup and Monoid?
There are at least three reasonable instances of Semigroup and Monoid for
ReaderT.
instance (Applicative m, Monoid a) => Monoid (ReaderT r m a) where
mempty = pure mempty
mappend a b = mappend <$> a <*> b
instance (Alternative m) => Monoid (ReaderT r m a) where
mempty = empty
mappend = (<|>)
instance (Monoid (m a)) => Monoid (ReaderT r m a) where
mempty = ReaderT $ mempty
mappend a b = ReaderT $ mappend a b
In the absence of a principled reason to prefer one over the others and a
general consensus, I think it’s better not to choose.
--
Dave Menendez

Ah, good point. I didn't think that there would be other instances. I'll
close the darcs request.
On Thu, 23 Mar 2017 at 6:58 am, David Menendez
On Tue, Mar 21, 2017 at 3:53 AM, Louis Pan
wrote: Hi all,
In my Glazier GUI library, I had to use newtype wrappers to create Semigroup and Monoid instances for ReaderT.
Is there a reason why ReaderT doesn't have an instance of Semigroup and Monoid?
There are at least three reasonable instances of Semigroup and Monoid for ReaderT.
instance (Applicative m, Monoid a) => Monoid (ReaderT r m a) where mempty = pure mempty mappend a b = mappend <$> a <*> b
instance (Alternative m) => Monoid (ReaderT r m a) where mempty = empty mappend = (<|>)
instance (Monoid (m a)) => Monoid (ReaderT r m a) where mempty = ReaderT $ mempty mappend a b = ReaderT $ mappend a b
In the absence of a principled reason to prefer one over the others and a general consensus, I think it’s better not to choose.
-- Dave Menendez
http://www.eyrie.org/~zednenem/ _______________________________________________
Haskell-Cafe mailing list
To (un)subscribe, modify options or view archives go to:
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Only members subscribed via the mailman list are allowed to post.
participants (2)
-
David Menendez
-
Louis Pan