Proposal: Add the orphan instance Monoid e => Monad ((, )e) to Data.Monoid

I propose adding an (orphan) instance of Monad for ((,) e) to Data.Monoid. Discussion deadline: 2 weeks from now (November 26) == Current State == No instance == The Issues == Control.Applicative already exports a compatible instance for Applicative for ((,) e), but there isn't a canonical place to get the compatible Monad. == Proposed enhancement == Add the following orphan instance to Data.Monoid. instance Monoid e => Monad ((,) e) where return a = (a, mempty) (w,a) >>= k = (mappend w w', b) where (w',b) = k a Why? Monoid isn't exported from the Prelude, so there is currently no place for this instance to live currently that doesn't render it an orphan. == Alternative == We could place this instance in Control.Monad.Instances which is where we've placed similar instances in the past. However, this would increase the likelihood of failure to properly import the instance for users, who would have to know to import both Data.Monoid and Control.Monad.Instances, rather than just Data.Monoid. Moreover in a separate active proposal I've just proposed moving all the Control.Monad.Instances instances out, so in the event that that proposal is adopted this would be unsatisfyingly the only instance there. -Edward

Er. Yep.
Thats what I get for writing it inline rather than pasting =)
On Sat, Nov 12, 2011 at 3:41 PM, Erik Hesselink
On Sat, Nov 12, 2011 at 21:29, Edward Kmett
wrote: instance Monoid e => Monad ((,) e) where return a = (a, mempty)
This should probably be: return a = (mempty, a)
Erik

On 12 November 2011 21:29, Edward Kmett
I propose adding an (orphan) instance of Monad for ((,) e) to Data.Monoid.
We could make it non-orphaned by putting it in GHC.Base. This does require putting the Monoid type class together with the [a], (a->b), (), (a,b), (a,b,c), (a,b,c,d) and (a,b,c,d,e) Monoid instances in GHC.Base. Data.Monoid then just re-exports the type class and instances. I'm +1 either way. BTW, it would be really nice if transformers could change its WriterT type from: newtype WriterT w m a = WriterT { runWriterT :: m (a, w) } to: newtype WriterT w m a = WriterT { runWriterT :: m (w, a) } so that it becomes compatible with the proposed ((,) w) instance. Ross, any chance that this could be done. Or does this break to much code? Cheers, Bas

Bas van Dijk writes:
BTW, it would be really nice if transformers could change its WriterT type from:
newtype WriterT w m a = WriterT { runWriterT :: m (a, w) }
to:
newtype WriterT w m a = WriterT { runWriterT :: m (w, a) }
so that it becomes compatible with the proposed ((,) w) instance.
Ross, any chance that this could be done. Or does this break to much code?
Just every module that uses WriterT, runWriterT or runWriter. Is the neatness worth it?

On Nov 12, 2011, at 6:56 PM, Paterson, Ross wrote:
Bas van Dijk writes:
Ross, any chance that this could be done. Or does this break to much code?
Just every module that uses WriterT, runWriterT or runWriter. Is the neatness worth it?
I am willing to update every module I control that uses WriterT. (Which is no small amount of code). - jeremy
participants (6)
-
Bas van Dijk
-
Brent Yorgey
-
Edward Kmett
-
Erik Hesselink
-
Jeremy Shaw
-
Paterson, Ross