Proposal: newtype for applicatives of monoids

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

Proposal: newtype for applicatives of monoids

David Feuer

Sorry for the terrible title, but I think we should add something like the following to Data.Monoid (I already mentioned this in the discussion of a Monoid instance for ZipList).

newtype Appl f m = Appl (f m)

instance (Applicative f, Monoid m) => Monoid (Appl f m) where
  mempty = Appl $ pure mempty
  mplus (Appl x) (Appl y) = Appl $ liftA2 mplus x y

It may be possible to use coercions to improve mplus; I haven't tried it.

This type is the same as WrappedApplicative from semigroupoids, do it might be best just to give it that name.


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

Re: Proposal: newtype for applicatives of monoids

Mario Blažević-3
On 07/26/2015 11:34 PM, David Feuer wrote:

>
> Sorry for the terrible title, but I think we should add something like
> the following to Data.Monoid (I already mentioned this in the
> discussion of a Monoid instance for ZipList).
>
> newtype Appl f m = Appl (f m)
>
> instance (Applicative f, Monoid m) => Monoid (Appl f m) where
>   mempty = Appl $ pure mempty
>   mplus (Appl x) (Appl y) = Appl $ liftA2 mplus x y
>

The method is called mappend, not mplus. Otherwise +1.


> It may be possible to use coercions to improve mplus; I haven't tried it.
>
> This type is the same as WrappedApplicative from semigroupoids, do it
> might be best just to give it that name.
>

The name Appl is the best fit with the recently-added Alt newtype, so I
prefer it.
_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
Reply | Threaded
Open this post in threaded view
|

Re: Proposal: newtype for applicatives of monoids

Christopher Allen
In reply to this post by David Feuer
Might as well capture all of 'em in one go.

+1 w/ aforementioned mappend/mplus fix.


On Sun, Jul 26, 2015 at 10:34 PM, David Feuer <[hidden email]> wrote:

Sorry for the terrible title, but I think we should add something like the following to Data.Monoid (I already mentioned this in the discussion of a Monoid instance for ZipList).

newtype Appl f m = Appl (f m)

instance (Applicative f, Monoid m) => Monoid (Appl f m) where
  mempty = Appl $ pure mempty
  mplus (Appl x) (Appl y) = Appl $ liftA2 mplus x y

It may be possible to use coercions to improve mplus; I haven't tried it.

This type is the same as WrappedApplicative from semigroupoids, do it might be best just to give it that name.


_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries




--
Chris Allen
Currently working on http://haskellbook.com

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

Re: Proposal: newtype for applicatives of monoids

John Wiegley-2
>>>>> Christopher Allen <[hidden email]> writes:

> Might as well capture all of 'em in one go.
> +1 w/ aforementioned mappend/mplus fix.

+1

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

Re: Proposal: newtype for applicatives of monoids

Edward Kmett-2
To offer a couple more colors for the bikeshed:

In my old monoids package, this exists as App:


In the newer reducers package, it has been shortened to Ap:


-Edward

On Mon, Aug 3, 2015 at 1:58 PM, John Wiegley <[hidden email]> wrote:
>>>>> Christopher Allen <[hidden email]> writes:

> Might as well capture all of 'em in one go.
> +1 w/ aforementioned mappend/mplus fix.

+1

John
_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries


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

Re: Proposal: newtype for applicatives of monoids

Bardur Arantsson-2
On 08/03/2015 09:14 PM, Edward Kmett wrote:

> To offer a couple more colors for the bikeshed:
>
> In my old monoids package, this exists as App:
>
> http://hackage.haskell.org/package/monoids-0.3.2/docs/Data-Monoid-Applicative.html
>
> In the newer reducers package, it has been shortened to Ap:
>
> http://hackage.haskell.org/package/reducers-3.10.3.2/docs/Data-Semigroup-Applicative.html
>

It *must* be App because apps are cool!

... I think?

Regards,


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

Re: Proposal: newtype for applicatives of monoids

David Casperson
In reply to this post by Mario Blažević-3
On 2015-08-03, Mario Blažević wrote:

> Date: Mon, 3 Aug 2015 10:22:56
> From: Mario Blažević <[hidden email]>
> To: [hidden email]
> Subject: Re: Proposal: newtype for applicatives of monoids
>
> On 07/26/2015 11:34 PM, David Feuer wrote:
>>
>> Sorry for the terrible title, but I think we should add something like the
>> following to Data.Monoid (I already mentioned this in the discussion of a
>> Monoid instance for ZipList).
>>
>> newtype Appl f m = Appl (f m)
>>
>> instance (Applicative f, Monoid m) => Monoid (Appl f m) where
>>   mempty = Appl $ pure mempty
>>   mplus (Appl x) (Appl y) = Appl $ liftA2 mplus x y
>>
>
> The method is called mappend, not mplus. Otherwise +1.
>
>
>> It may be possible to use coercions to improve mplus; I haven't tried it.
>>
>> This type is the same as WrappedApplicative from semigroupoids, do it might
>> be best just to give it that name.
+1, with mappend.

(I just tripped over the Monad instance of the same thing. It's
  very nice to be able to use (<>) on something like Monad m =>
  Control.Monad.Trans.Exception m () .)

Cheers,
David
--
David Casperson, PhD, R.P.,                  |  [hidden email]
Associate Professor and Chair,               |  (250)   960-6672 Fax 960-5544
Computer Science                             |  3333 University Way
University of Northern British Columbia      |  Prince George, BC   V2N 4Z9
                                              |  CANADA

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

Re: Proposal: newtype for applicatives of monoids

David Feuer
In reply to this post by Edward Kmett-2

I don't want to take App because it's probably the most popular name for representing function application in ASTs.

On Aug 3, 2015 3:14 PM, "Edward Kmett" <[hidden email]> wrote:
To offer a couple more colors for the bikeshed:

In my old monoids package, this exists as App:


In the newer reducers package, it has been shortened to Ap:


-Edward

On Mon, Aug 3, 2015 at 1:58 PM, John Wiegley <[hidden email]> wrote:
>>>>> Christopher Allen <[hidden email]> writes:

> Might as well capture all of 'em in one go.
> +1 w/ aforementioned mappend/mplus fix.

+1

John
_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries


_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries


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

Re: Proposal: newtype for applicatives of monoids

David Feuer
In reply to this post by Edward Kmett-2

Ap seems a good name, and it's already used for that, so I'd support that bike shed color.

On Aug 3, 2015 3:14 PM, "Edward Kmett" <[hidden email]> wrote:
To offer a couple more colors for the bikeshed:

In my old monoids package, this exists as App:


In the newer reducers package, it has been shortened to Ap:


-Edward

On Mon, Aug 3, 2015 at 1:58 PM, John Wiegley <[hidden email]> wrote:
>>>>> Christopher Allen <[hidden email]> writes:

> Might as well capture all of 'em in one go.
> +1 w/ aforementioned mappend/mplus fix.

+1

John
_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries


_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries


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

Re: Proposal: newtype for applicatives of monoids

Andreas Abel
+1 to Ap.

On 04.08.2015 05:21, David Feuer wrote:

> Ap seems a good name, and it's already used for that, so I'd support
> that bike shed color.
>
> On Aug 3, 2015 3:14 PM, "Edward Kmett" <[hidden email]
> <mailto:[hidden email]>> wrote:
>
>     To offer a couple more colors for the bikeshed:
>
>     In my old monoids package, this exists as App:
>
>     http://hackage.haskell.org/package/monoids-0.3.2/docs/Data-Monoid-Applicative.html
>
>     In the newer reducers package, it has been shortened to Ap:
>
>     http://hackage.haskell.org/package/reducers-3.10.3.2/docs/Data-Semigroup-Applicative.html
>
>     -Edward
>
>     On Mon, Aug 3, 2015 at 1:58 PM, John Wiegley <[hidden email]
>     <mailto:[hidden email]>> wrote:
>
>         >>>>> Christopher Allen <[hidden email] <mailto:[hidden email]>> writes:
>
>         > Might as well capture all of 'em in one go.
>         > +1 w/ aforementioned mappend/mplus fix.
>
>         +1
>
>         John
>         _______________________________________________
>         Libraries mailing list
>         [hidden email] <mailto:[hidden email]>
>         http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
>
>
>
>     _______________________________________________
>     Libraries mailing list
>     [hidden email] <mailto:[hidden email]>
>     http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
>
>
>
> _______________________________________________
> Libraries mailing list
> [hidden email]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
>


--
Andreas Abel  <><      Du bist der geliebte Mensch.

Department of Computer Science and Engineering
Chalmers and Gothenburg University, Sweden

[hidden email]
http://www2.tcs.ifi.lmu.de/~abel/
_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
Reply | Threaded
Open this post in threaded view
|

Re: Proposal: newtype for applicatives of monoids

Oleg Grenrus
There is also http://hackage.haskell.org/package/free-4.12.1/docs/Control-Applicative-Free.html#t:Ap, which is totally different thing, yet related to Applicative.

reducers Ap has getApp field name, which is probably copy&paste mistake:

In that light I’d prefer
- Appl with getAppl,
- Ap unchanged in free package
- App left free

On 05 Aug 2015, at 12:15, Andreas Abel <[hidden email]> wrote:

+1 to Ap.

On 04.08.2015 05:21, David Feuer wrote:
Ap seems a good name, and it's already used for that, so I'd support
that bike shed color.

On Aug 3, 2015 3:14 PM, "Edward Kmett" <[hidden email]
<[hidden email]>> wrote:

   To offer a couple more colors for the bikeshed:

   In my old monoids package, this exists as App:

   http://hackage.haskell.org/package/monoids-0.3.2/docs/Data-Monoid-Applicative.html

   In the newer reducers package, it has been shortened to Ap:

   http://hackage.haskell.org/package/reducers-3.10.3.2/docs/Data-Semigroup-Applicative.html

   -Edward

   On Mon, Aug 3, 2015 at 1:58 PM, John Wiegley <[hidden email]
   <[hidden email]>> wrote:

       >>>>> Christopher Allen <[hidden email] <[hidden email]>> writes:

       > Might as well capture all of 'em in one go.
       > +1 w/ aforementioned mappend/mplus fix.

       +1

       John
       _______________________________________________
       Libraries mailing list
       [hidden email] <[hidden email]>
       http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries



   _______________________________________________
   Libraries mailing list
   [hidden email] <[hidden email]>
   http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries



_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries



--
Andreas Abel  <><      Du bist der geliebte Mensch.

Department of Computer Science and Engineering
Chalmers and Gothenburg University, Sweden

[hidden email]
http://www2.tcs.ifi.lmu.de/~abel/
_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries



_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries

signature.asc (859 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Proposal: newtype for applicatives of monoids

Petr Pudlák
In reply to this post by Edward Kmett-2

IIRC the accessor is still called getApp in reducers, which is slightly inconsistent. Perhaps it'd be worth fixing on some future release that will bring other incompatible changes.

Thanks
Petr

Dne po 3. 8. 2015 21:14 uživatel Edward Kmett <[hidden email]> napsal:

To offer a couple more colors for the bikeshed:

In my old monoids package, this exists as App:

http://hackage.haskell.org/package/monoids-0.3.2/docs/Data-Monoid-Applicative.html

In the newer reducers package, it has been shortened to Ap:

http://hackage.haskell.org/package/reducers-3.10.3.2/docs/Data-Semigroup-Applicative.html

-Edward

On Mon, Aug 3, 2015 at 1:58 PM, John Wiegley <[hidden email]> wrote:

>>>>> Christopher Allen <[hidden email]> writes:

> Might as well capture all of 'em in one go.
> +1 w/ aforementioned mappend/mplus fix.

+1

John

_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries

_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries



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

Re: Proposal: newtype for applicatives of monoids

Edward Kmett-2
It was fixed in HEAD for a while. I've now shipped that fix as part of 3.11.

-Edward

On Wed, Aug 12, 2015 at 4:09 AM, Petr Pudlák <[hidden email]> wrote:

IIRC the accessor is still called getApp in reducers, which is slightly inconsistent. Perhaps it'd be worth fixing on some future release that will bring other incompatible changes.

Thanks
Petr

Dne po 3. 8. 2015 21:14 uživatel Edward Kmett <[hidden email]> napsal:

To offer a couple more colors for the bikeshed:

In my old monoids package, this exists as App:

http://hackage.haskell.org/package/monoids-0.3.2/docs/Data-Monoid-Applicative.html

In the newer reducers package, it has been shortened to Ap:

http://hackage.haskell.org/package/reducers-3.10.3.2/docs/Data-Semigroup-Applicative.html

-Edward

On Mon, Aug 3, 2015 at 1:58 PM, John Wiegley <[hidden email]> wrote:

>>>>> Christopher Allen <[hidden email]> writes:

> Might as well capture all of 'em in one go.
> +1 w/ aforementioned mappend/mplus fix.

+1

John

_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries

_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries




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

Re: Proposal: newtype for applicatives of monoids

Petr Pudlák

Thanks!

Petr


Dne st 12. 8. 2015 17:54 uživatel Edward Kmett <[hidden email]> napsal:
It was fixed in HEAD for a while. I've now shipped that fix as part of 3.11.

-Edward

On Wed, Aug 12, 2015 at 4:09 AM, Petr Pudlák <[hidden email]> wrote:

IIRC the accessor is still called getApp in reducers, which is slightly inconsistent. Perhaps it'd be worth fixing on some future release that will bring other incompatible changes.

Thanks
Petr

Dne po 3. 8. 2015 21:14 uživatel Edward Kmett <[hidden email]> napsal:

To offer a couple more colors for the bikeshed:

In my old monoids package, this exists as App:

http://hackage.haskell.org/package/monoids-0.3.2/docs/Data-Monoid-Applicative.html

In the newer reducers package, it has been shortened to Ap:

http://hackage.haskell.org/package/reducers-3.10.3.2/docs/Data-Semigroup-Applicative.html

-Edward

On Mon, Aug 3, 2015 at 1:58 PM, John Wiegley <[hidden email]> wrote:

>>>>> Christopher Allen <[hidden email]> writes:

> Might as well capture all of 'em in one go.
> +1 w/ aforementioned mappend/mplus fix.

+1

John

_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries

_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries




_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries