Prophet
Prophet

Reputation: 186

Why is Data.Map.Map not a Bifunctor?

When storing data in a Map, I was recently looking for a Bitraversable instance, since I wanted to traverse over both keys and values. To my surprise, I found out that Map does not even have a Bifunctor instance, even though implementations for both first (mapKeys) and second (map) exist.

Is there a specific reason for this or was this decision just made to minimize dependencies?

Thanks

Upvotes: 1

Views: 134

Answers (1)

Daniel Wagner
Daniel Wagner

Reputation: 153247

The implementation for left (did you actually mean first? I'm going to write left instead of first everywhere) does not exist, because mapKeys has a constraint:

Ord k2 => (k1 -> k2) -> Map k1 a -> Map k2 a

left must work for any pair of types k1 and k2.

Upvotes: 7

Related Questions