[Haskell-cafe] ANN: bimap 0.1 - a bidirectional map

Neil Mitchell ndmitchell at gmail.com
Mon Feb 4 03:56:28 EST 2008

Hi Stuart,

> Data.Bimap is a data structure that represents a bidirectional mapping
> between two key types. A bimap has two type parameters; each value in
> the bimap is associated with exactly one value of the opposite type.
> In other words, it's a bijection between (subsets of) its argument
> types.

Very  handy, I actually wanted something similar myself a few days ago
and came up with:


A few design differences from your one:

* I called my module BiMap" rather than "Bimap" - I debated this with
a collegue, and we settled on the capital M, but it was a very close

* I have no L/R and Either variants. I decided it was better to be a
superset of Data.Map, and then have lookupRev/memberRev functions for
the R versions. Do you think anyone is likely to use the Either
variant, without a constant Left or Right in the code? Is this an
artefact of how its easier to code, rather than to use?

* I didn't push my Bimap to completion, because I am too lazy, and
hoped others would. Only the methods I needed were implemented. Many
thanks for doing this work!



More information about the Haskell-Cafe mailing list