Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
[Caml-list] sharing problem ...
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2004-01-26 (13:27)
From: Damien Doligez <damien.doligez@i...>
Subject: Re: [Caml-list] sharing problem ...
On Monday, January 26, 2004, at 11:43 AM, Pietro Abate wrote:

> I'm trying to implement a (string * set) hashtbl
> where some element (set) should be shared between different
> objects.
> the main point is that when I clone an object I want to duplicate
> some sets and shared others (sticky sets)

This doesn't make sense because your set type is built from the
standard library's Set module.  Thus your sets are purely applicative:
you cannot modify them with side-effects.

Shared or not, the elements of a1 will not change when you change
the elements of a2, because changing the elements of a2 doesn't
change the elements themselves, it only replaces them with new
elements (which are not shared, by definition).

That can be seen in your code:

                 sets <- MyMap.remove name sets;
                 sets <- MyMap.add name (set',t) sets

You don't change the shared set, you remove it from the map and then
add a new one under the same name.

If you really need mutable sets, maybe you should use the Hashtbl
module instead of Set.

-- Damien

To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: