Re: [Haskell-cafe] Re: Bi-directional Maps

2007-09-02 Thread Hugh Perkins
Just noticed, erlang has the second kind of bimap (a bijection?)
built into each process:

From http://www.erlang.org/doc/reference_manual/processes.html :

10.9 Process Dictionary

Each process has its own process dictionary, accessed by calling the
following BIFs:

put(Key, Value)
get(Key)
get()
get_keys(Value)
erase(Key)
erase()

That's interesting.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: Bi-directional Maps

2007-08-21 Thread Hugh Perkins
 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.

Or... have the possibility of returning a list of values.

Arguably there are two possible implementations, one that enforces
one-to-one mapping, and one which allows multiple values, in either
direction.

But how can you change a value if there are non-unique keys?.  Well,
you dont change a value, you change a list of values ;-)

So, let's say our bimap is:

1,1
1,2
5,2
5,3

then:

bimap_getvalue ourbimap 1 gives  [1,2]
bimap_getkey ourbimap 2 gives [1,5]

Executing bimap_setkey ourbimap 2 [1,4] changes the bimap to:

1,1
1,2
4,2
5,3
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: Bi-directional Maps

2007-08-21 Thread Albert Y. C. Lai

apfelmus wrote:

Hugh Perkins wrote:

Arguably there are two possible implementations, one that enforces
one-to-one mapping, and one which allows multiple values, in either
direction.


Terminology reminder :)
- the latter is called (binary) relation
  http://en.wikipedia.org/wiki/Binary_relation
- the former would be a bijection
  http://en.wikipedia.org/wiki/Bijective_map


Following a great tradition,

That's just semantics.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: Bi-directional Maps

2007-08-20 Thread Rich Neswold
On 8/20/07, apfelmus [EMAIL PROTECTED] 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: [EMAIL PROTECTED]
AIM: rnezzy
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe