[GHC] #13572: Add ArgMin / ArgMax pattern synonyms
GHC
ghc-devs at haskell.org
Thu Apr 13 18:35:00 UTC 2017
#13572: Add ArgMin / ArgMax pattern synonyms
-------------------------------------+-------------------------------------
Reporter: Iceland_jack | Owner: (none)
Type: feature request | Status: new
Priority: normal | Milestone:
Component: libraries/base | Version: 8.0.1
Resolution: | Keywords:
| PatternSynonyms
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 changed by Iceland_jack:
@@ -20,1 +20,1 @@
- pattern ArgMax [maxArg, maxValue} = Max (Arg maxArg maxValue)
+ pattern ArgMax {maxArg, maxValue} = Max (Arg maxArg maxValue)
New description:
{{{#!hs
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
[https://github.com/energyflowanalysis/efa-2.1/blob/3eb86c0b6b2d2fb66cd5b76ce5c0437d42f8cdf8/sandbox/delaunay/HalfPlaneMap.hs#L181
this]
{{{#!hs
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
{{{#!hs
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)
}}}
--
--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/13572#comment:1>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the ghc-tickets
mailing list