Opened 2 weeks ago

Last modified 13 days ago

#13572 new feature request

Add ArgMin / ArgMax pattern synonyms

Reported by: Iceland_jack Owned by:
Priority: normal Milestone:
Component: libraries/base Version: 8.0.1
Keywords: PatternSynonyms Cc: core-libraries-committee@…
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:

Description (last modified by Iceland_jack)

import Data.Semigroup

pattern ArgMin :: a -> b -> ArgMin a b
pattern ArgMin a b = Min (Arg a b)

pattern ArgMax :: a -> b -> ArgMax a b
pattern ArgMax a b = Max (Arg a b)

Or even record pattern synonyms, à la this

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)

and we can define

import Data.Semigroup.Foldable

argmin :: Ord k => Foldable1 f => (a -> k) -> (f a -> a)
argmin f = minValue . foldMap1 (\a -> ArgMin (f a) a)

argmax :: Ord k => Foldable1 f => (a -> k) -> (f a -> a)
argmax f = maxValue . foldMap1 (\a -> ArgMax (f a) a)

Change History (2)

comment:1 Changed 13 days ago by Iceland_jack

Description: modified (diff)

comment:2 Changed 13 days ago by bgamari

Cc: core-libraries-committee@… added

Where are you suggesting these are added? I think this should really go through the usual libraries process.

Note: See TracTickets for help on using tickets.