Quantcast

Add Arg{Min,Max} pattern synonyms to Data.Semigroup

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Add Arg{Min,Max} pattern synonyms to Data.Semigroup

Baldur Blöndal
Add (explicitly-bidirectional record) pattern synonyms to Data.Semigroup:

pattern ArgMin :: a -> b -> ArgMin a b pattern ArgMin {minArg, minValue} = Min (Arg minArg minValue) 

pattern ArgMax :: a -> b -> ArgMax a b pattern ArgMax {maxArg, maxValue} = Max (Arg maxArg maxValue)

As described in https://ghc.haskell.org/trac/ghc/ticket/13572

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

Re: Add Arg{Min,Max} pattern synonyms to Data.Semigroup

Edward Kmett-2
I'm personally weakly +1 on this. It makes the combination of Arg and Max much more convenient to use and points directly to how to use it without code duplication. The potential downside is using a big scary extension in what will become a fairly mainstream module in 8.4, but I think we can phrase our way around the issue when it comes to the libraries part of Haskell-Prime.

This opens the door to possibly being smarter about the existing Data.Monoid.First (and Last), encoding them as pattern synonyms for Maybe (Data.Semigroup.First a) (or Last) as well, but we'd likely need to give that a lot more thought / testing.

-Edward

On Thu, Apr 13, 2017 at 3:22 PM, Baldur Blöndal <[hidden email]> wrote:
Add (explicitly-bidirectional record) pattern synonyms to Data.Semigroup:

pattern ArgMin :: a -> b -> ArgMin a b pattern ArgMin {minArg, minValue} = Min (Arg minArg minValue) 

pattern ArgMax :: a -> b -> ArgMax a b pattern ArgMax {maxArg, maxValue} = Max (Arg maxArg maxValue)

As described in https://ghc.haskell.org/trac/ghc/ticket/13572

_______________________________________________
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
|  
Report Content as Inappropriate

Re: Add Arg{Min,Max} pattern synonyms to Data.Semigroup

Ivan Lazar Miljenovic
On 18 April 2017 at 22:52, Edward Kmett <[hidden email]> wrote:

> I'm personally weakly +1 on this. It makes the combination of Arg and Max
> much more convenient to use and points directly to how to use it without
> code duplication. The potential downside is using a big scary extension in
> what will become a fairly mainstream module in 8.4, but I think we can
> phrase our way around the issue when it comes to the libraries part of
> Haskell-Prime.
>
> This opens the door to possibly being smarter about the existing
> Data.Monoid.First (and Last), encoding them as pattern synonyms for Maybe
> (Data.Semigroup.First a) (or Last) as well, but we'd likely need to give
> that a lot more thought / testing.

I've actually been considering that recently.

I'm weakly +1 on this proposal as well.

>
> -Edward
>
> On Thu, Apr 13, 2017 at 3:22 PM, Baldur Blöndal <[hidden email]> wrote:
>>
>> Add (explicitly-bidirectional record) pattern synonyms to Data.Semigroup:
>>
>> pattern ArgMin :: a -> b -> ArgMin a b pattern ArgMin {minArg, minValue} =
>> Min (Arg minArg minValue)
>>
>> pattern ArgMax :: a -> b -> ArgMax a b pattern ArgMax {maxArg, maxValue} =
>> Max (Arg maxArg maxValue)
>>
>> As described in https://ghc.haskell.org/trac/ghc/ticket/13572
>>
>> _______________________________________________
>> 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
>



--
Ivan Lazar Miljenovic
[hidden email]
http://IvanMiljenovic.wordpress.com
_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Add Arg{Min,Max} pattern synonyms to Data.Semigroup

Baldur Blöndal
In reply to this post by Edward Kmett-2
> This opens the door to possibly being smarter about the existing Data.Monoid.First (and Last), encoding them as pattern synonyms for Maybe (Data.Semigroup.First a) (or Last) as well, but we'd likely need to give that a lot more thought / testing.

Yes First/Last is a good use for pattern synonyms

> The potential downside is using a big scary extension in what will become a fairly mainstream module in 8.4, but I think we can phrase our way around the issue when it comes to the libraries part of Haskell-Prime.

As for this proposal I am in no hurry to see it implemented, I figured pattern synonyms would take time to get adopted to base. What do you mean by "phrase our way" around the issue?

(The pattern synonyms could be added to the documentation. . "If you are okay with PatternSynonyms..")

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

Re: Add Arg{Min,Max} pattern synonyms to Data.Semigroup

Mario Blažević
In reply to this post by Edward Kmett-2
On 2017-04-18 08:52 AM, Edward Kmett wrote:
> I'm personally weakly +1 on this. It makes the combination of Arg and
> Max much more convenient to use and points directly to how to use it
> without code duplication. The potential downside is using a big scary
> extension in what will become a fairly mainstream module in 8.4, but I
> think we can phrase our way around the issue when it comes to the
> libraries part of Haskell-Prime.

        I'm (-1) until I'm convinced that the phrasing-around approach works.
Can you spell it out?


> This opens the door to possibly being smarter about the existing
> Data.Monoid.First (and Last), encoding them as pattern synonyms for
> Maybe (Data.Semigroup.First a) (or Last) as well, but we'd likely need
> to give that a lot more thought / testing.
>
> -Edward
>
> On Thu, Apr 13, 2017 at 3:22 PM, Baldur Blöndal <[hidden email]
> <mailto:[hidden email]>> wrote:
>
>     Add (explicitly-bidirectional record) pattern synonyms to
>     Data.Semigroup:
>
>     pattern ArgMin :: a -> b -> ArgMin a b pattern ArgMin {minArg,
>     minValue} = Min (Arg minArg minValue)
>
>     pattern ArgMax :: a -> b -> ArgMax a b pattern ArgMax {maxArg,
>     maxValue} = Max (Arg maxArg maxValue)
>
>     As described in https://ghc.haskell.org/trac/ghc/ticket/13572
>     <https://ghc.haskell.org/trac/ghc/ticket/13572>
>
_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
Loading...