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

David Feuer david.feuer at gmail.com
Fri Jul 8 17:49:12 UTC 2016


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

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.

David Feuer


More information about the Libraries mailing list