ANN: bimap 0.1 - a bidirectional map

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. The API is loosely based on Data.Map; feedback and suggestions are most welcome. So far I've only tested it on GHC 6.6 on Linux/x86, with Cabal 1.2.3.0. Let me know if it works or breaks on other configurations. Hackage: http://hackage.haskell.org/cgi-bin/hackage-scripts/package/bimap-0.1 Haddocks: http://code.haskell.org/~scook0/haddock/bimap/ Darcs: darcs get http://code.haskell.org/bimap Stuart Cook

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: http://www.cs.york.ac.uk/fp/darcs/firstify/Yhc/Core/Firstify/Mitchell/BiMap.... 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 call. * 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! Thanks Neil

On Mon, Feb 4, 2008 at 7:56 PM, Neil Mitchell
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 call.
Mine was also originally BiMap, but I thought the capital M looked a little ugly, so I changed it.
* 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 initially had only the Either variants, because that was easier to code, and I thought it would make the interface cleaner. Then when I started writing tests, I realised that this was a pain, and I went back and added the L/R variants. I never bothered to remove the Either variants, because the L/R versions are (currently) implemented in terms of them anyway. I was thinking of having another module, Data.Bimap.Asymmetric, that would expose an interface more like that of Data.Map (i.e. biased towards treating the left type as the key), but I decided it was better to get the first release out as soon as possible. Thanks for the feedback, Stuart

+1
I needed this quite a lot in my own code but didn't take the time to
generalize it into a releasable package. Thanks!
On Feb 4, 2008 4:40 AM, Stuart Cook
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.
The API is loosely based on Data.Map; feedback and suggestions are most welcome.
So far I've only tested it on GHC 6.6 on Linux/x86, with Cabal 1.2.3.0. Let me know if it works or breaks on other configurations.
Hackage: http://hackage.haskell.org/cgi-bin/hackage-scripts/package/bimap-0.1
Haddocks: http://code.haskell.org/~scook0/haddock/bimap/
Darcs: darcs get http://code.haskell.org/bimap
Stuart Cook _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
participants (3)
-
Neil Mitchell
-
Stuart Cook
-
Thomas Schilling