[Haskell-cafe] Re: Bi-directional Maps
Rich Neswold
rich.neswold at gmail.com
Mon Aug 20 14:46:15 EDT 2007
On 8/20/07, apfelmus <apfelmus at quantentunnel.de> wrote:
>
> Andrew Wagner wrote:
> > It occurred to me that it would be useful to explicitly
> > have a Bi-directional Map, which does the maintenance of keeping the
> > Maps synchronized behind the scenes. Thus, Bimap was born!
>
> ... most of the map functions (including update above) probably won't
> work anyway, what should
>
> left_insertWith (\new old -> new) 'a' 1 (fromList [('a',2),('b',1)])
>
> do? I can't yield
>
> fromList [('a',1),('b',1)]
>
> since 1 has two keys now.
>
Exactly. For this to work there needs to be the constraint that there's a
one-to-one mapping in each direction. The Bimap should have the uniqueness
promise that "Set (k, v)" gives. Yet you should be able to search on either
tuple value.
--
Rich
JID: rich at neswold.homeunix.net
AIM: rnezzy
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20070820/38ba6bac/attachment.htm
More information about the Haskell-Cafe
mailing list