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

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

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
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 Libraries@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries

On 18 April 2017 at 22:52, Edward Kmett
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
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 Libraries@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
_______________________________________________ Libraries mailing list Libraries@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
-- Ivan Lazar Miljenovic Ivan.Miljenovic@gmail.com http://IvanMiljenovic.wordpress.com

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.
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
Yes First/Last is a good use for pattern synonyms 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..")

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
mailto:baldurpet@gmail.com> 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
participants (4)
-
Baldur Blöndal
-
Edward Kmett
-
Ivan Lazar Miljenovic
-
Mario Blažević