Description

(Note: Every claim here referring to Data.Map.map applies equally well to Data.IntMap.map.)

I believe that Data.Map.map is a misfeature and should be deprecated or removed.

Its name clashes with an extremely commonly-used Prelude function. This makes the first import of Data.Map into an existing module very expensive. Either all existing instances of "map" need to be qualified, or the import of Data.Map needs to be qualified (which works, but makes (!) and () unnecessarily inelegant), or the import must hide map.

There is an easy way to get at the functionality which is already implemented: use fmap.

Data.Set.map and Data.IntSet.map have similar problems, however you can't just "use fmap" in that case. I don't have a good solution except to rename these.

Data.Map.null also clashes with the Prelude, and should be reconsidered. However, again, there isn't a simple workaround, and there are many more overloadings of null (e.g. Data.ByteString). It's also likely that null is used far less than map, so the cost of a clash is much lower.

Oldest firstNewest firstThreaded

Comments only

Change History (8)

Its name clashes with an extremely commonly-used Prelude function. This makes the first import of Data.Map into an existing module very expensive. Either all existing instances of "map" need to be qualified, or the import of Data.Map needs to be qualified (which works, but makes (!) and () unnecessarily inelegant), or the import must hide map.

Data.Map is supposed to be imported qualified. As it says in the haddock docsData.Map is supposed to be imported qualified:

import Data.Map (Map)
import qualified Data.Map as Map

then you can use Map.map which now doesn't clash with anything and you don't need to change any existing stuff in your code.

If you don't like using the ugly Map.! and Map.\\ you can always use Map.lookup and Map.difference instead or if you really want those operators and not the array / list versions then you can import them unqualified and hide or qualify the array / list versions.

I guess the problem is that the module as a whole doesn't hit a sweet spot. If it's meant to be imported qualified, then the operators are horrible. If it's allowed to be imported unqualified, then the names clash. Something has to give.

The "right" answer is, of course, a well-designed Edison-like abstraction layer which makes this all go away, so perhaps this isn't the right forum for the complaint.