-
Notifications
You must be signed in to change notification settings - Fork 8
Please add Semigroup and Monoid instances #10
Copy link
Copy link
Closed
Description
[original issue 38 by @louispan]
Would it make sense to add Semigroup and Monoid instances to the transformer newtype wrappers?
See https://mail.haskell.org/pipermail/haskell-cafe/2017-March/126588.html
Eg.
instance (Applicative m, Monoid a) => Monoid (ReaderT r m a)
mempty = pure mempty
mappend = liftA2 mappend
instance (Applicative m, Semigroup a) => Semigroup (ReaderT r m a)
(<>) = liftA2 (<>)and similar for the other transformer newtype wrappers.
David Feuer notes that the Semigroup instance actually only need an "Apply" instance, but I'm not sure how you'll be able to add Apply to the transformer package.
Olaf Klinke notes that in general:
instance (Semigroup a, Applicative f) => Semigroup (f a) where
(<>) = liftA2 (<>)but unfortunately that will lead to overlapping instances.
Therefore, I feel adding the instances to the transformer newtypes is a good middle ground.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels