More Data.Set and Data.Map operations

David Feuer david.feuer at gmail.com
Sun Aug 7 18:14:31 UTC 2016


I had another idea for an operation that covers most of the likely
use-cases for mergeWithKey, but without its danger and with a
substantially more informative type signature. The only downside is
that it's not even close to Haskell 98.

data MergeTactic k x y where
  Drop :: MergeTactic k x y
  Preserve :: MergeTactic k x x
  MapFilter :: (k -> x -> Maybe y) -> MergeTactic k x y

generalMerge :: Ord k
             => (k -> a -> b -> Maybe c) -> MergeTactic k a c ->
MergeTactic k b c
             -> Map k a -> Map k b -> Map k c

How do people feel about exporting this for GHC?

On Sun, Aug 7, 2016 at 12:32 AM, Oleg Grenrus <oleg.grenrus at iki.fi> wrote:
> -1 on unionWithMapping/Key. There is already mergeWithKey (and there’s pull request to `these` to use it, I’d just hadn’t time to look it thru properly and apply).
>
> - Oleg Grenrus (co-maintainer of these)
>
>> On 07 Aug 2016, at 06:15, David Feuer <david.feuer at gmail.com> wrote:
>>
>> Cale Gibbard and Ryan Trinkle are interested in adding some more
>> operations they say will be useful in their work. Note that
>> unionWithMapping is intended to enable an efficient implementation of
>> alignWith in Data.Align in the `these` package.
>>
>> Set:
>>
>> filterIncreasing :: Ord a => (a -> Bool) -> Set a -> Set a
>> filterDecreasing :: Ord a => (a -> Bool) -> Set a -> Set a
>> partitionIncreasing :: Ord a => (a -> Bool) -> Set a -> (Set a, Set a)
>>
>> Map:
>>
>> filterKeysIncreasing :: Ord k => (k -> Bool) -> Map k a -> Map k a
>> filterKeysDecreasing :: Ord k => (k -> Bool) -> Map k a -> Map k a
>> partitionKeysIncreasing :: Ord k => (k -> Bool) -> Map k a -> (Map k a, Map k a)
>>
>> traverseMaybe :: Applicative f => (a -> f (Maybe b)) -> Map k a -> f (Map k b)
>>
>> alterMany :: Ord k => (a -> Maybe b -> Maybe b) -> Map k a -> Map k b -> Map k b
>>
>> alterManyA :: (Applicative f, Ord k) => (a -> Maybe b -> f (Maybe b))
>> -> Map k a -> Map k b -> f (Map k b)
>>
>> unionWithMapping :: Ord k => (a -> c) -> (b -> c) -> (a -> b -> c) ->
>> Map k a -> Map k b -> Map k c
>>
>> unionWithKeyMapping :: Ord k => (k -> a -> c) -> (k -> b -> c) -> (k
>> -> a -> b -> c)
>> -> Map k a -> Map k b -> Map k c
>> _______________________________________________
>> Libraries mailing list
>> Libraries at haskell.org
>> http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
>


More information about the Libraries mailing list