Proposal and discussion: Deprecate Data.Set.mapMonotonic and Data.Map.mapKeysMonotonic; add correctly named functions

Ivan Lazar Miljenovic ivan.miljenovic at gmail.com
Fri Jul 8 23:18:19 UTC 2016


On 9 July 2016 at 03:49, David Feuer <david.feuer at gmail.com> wrote:
> We currently have a function mapMonotonic in Data.Set and one called
> mapKeysMonotonic in Data.Map. These names are confusing for two
> reasons:
>
> 1. In some mathematical contexts, a function is considered monotonic
> if it's *either* increasing or decreasing.
>
> 2. Even where monotonic specifically means *increasing*, it generally
> does *not* specifically mean *strictly increasing*.
>
> The functions in question work when, and only when, the given function
> is strictly increasing on the elements/keys in the set/map.
>
> I'd like to DEPRECATE these functions, and add new ones:
>
> Data.Set: mapStrictlyIncreasing and mapStrictlyDecreasing
> Data.Map: mapKeysStrictlyIncreasing and mapKeysStrictlyDecreasing

With the latter function also flipping the underlying tree structure?

> Data.Map presents another possibility, however. We could make the
> replacements more general, giving them types
>
> Ord k => (k -> v -> (k', v')) -> Map k v -> Map k' v'
>
> and allowing the user to map over both keys and values in one pass.

Though IIUC this provides no way of specifying that "I'm sure this
function has a 1-1 monotonic relationship so you can just update the
keys without changing the structure" (in the sense of there's no way
to distinguish between the increasing and decreasing sense).

Overall, I'm about +0.5 from the naming sense of the current
functions, but have used these in the past.


-- 
Ivan Lazar Miljenovic
Ivan.Miljenovic at gmail.com
http://IvanMiljenovic.wordpress.com


More information about the Libraries mailing list