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

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

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

Edward Kmett-2
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

_______________________________________________
Libraries mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/libraries
Reply | Threaded
Open this post in threaded view
|

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

Erik Hesselink
On Sat, Nov 12, 2011 at 21:29, Edward Kmett <[hidden email]> wrote:
> instance Monoid e => Monad ((,) e) where
>         return a = (a, mempty)

This should probably be:
    return a = (mempty, a)

Erik

_______________________________________________
Libraries mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/libraries
Reply | Threaded
Open this post in threaded view
|

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

Edward Kmett-2
Er. Yep.

Thats what I get for writing it inline rather than pasting =)

On Sat, Nov 12, 2011 at 3:41 PM, Erik Hesselink <[hidden email]> wrote:
On Sat, Nov 12, 2011 at 21:29, Edward Kmett <[hidden email]> wrote:
> instance Monoid e => Monad ((,) e) where
>         return a = (a, mempty)

This should probably be:
   return a = (mempty, a)

Erik


_______________________________________________
Libraries mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/libraries
Reply | Threaded
Open this post in threaded view
|

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

Bas van Dijk-2
In reply to this post by Edward Kmett-2
On 12 November 2011 21:29, Edward Kmett <[hidden email]> wrote:
> 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

_______________________________________________
Libraries mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/libraries
Reply | Threaded
Open this post in threaded view
|

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

Ross Paterson-2
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?
_______________________________________________
Libraries mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/libraries
Reply | Threaded
Open this post in threaded view
|

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

Jeremy Shaw-3

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


_______________________________________________
Libraries mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/libraries
Reply | Threaded
Open this post in threaded view
|

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

Brent Yorgey-2
In reply to this post by Edward Kmett-2
On Sat, Nov 12, 2011 at 03:29:47PM -0500, Edward Kmett wrote:
> I propose adding an (orphan) instance of Monad for ((,) e) to Data.Monoid.

+1

_______________________________________________
Libraries mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/libraries