Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] Oo.id
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: james woodyatt <jhw@w...>
Subject: Re: [Caml-list] Oo.id
On Friday, Oct 4, 2002, at 00:58 US/Pacific, Jacques Garrigue wrote:
> From: james woodyatt <jhw@wetware.com>
>> Reading the source code in the caml distribution really didn't help me
>> understand what's going on, so I'm asking the list again:
>>
>> 	Why does every class object contain field with unique integer?
>
> [...]
> So we had to add a unique id to each object, which is used for
> primitive equality and comparison functions. This also seemed
> reasonable to make it available to the user, for use in indexed data
> structures.

Wow.  Okay, I just tried some stuff out:

> [kallisti:~] jhw% ocaml
>         Objective Caml version 3.06
>
> # class foo = object method foo = () end;;
> class foo : object method foo : unit end
> # let a = new foo and b = new foo;;
> val a : foo = <obj>
> val b : foo = <obj>
> # a < b;;
> - : bool = true
> # b < a;;
> - : bool = false

This is one of those interesting little oddities in Objective Caml that 
is really not apparent from reading the documentation.  Thanks for 
explaining it.

One suggestion: it might help to have a brief discussion of Oo.id in 
the tutorial about advanced uses of classes and modules.  I would put 
it into the section about the subject/observer pattern.  Since objects 
all have unique identifiers, the subject could use a map of identifiers 
to observers rather than a list of observers.  This would allow you to 
easily write a remove_observer method that didn't have to iterate over 
the whole list.


-- 
j h woodyatt <jhw@wetware.com>
markets are only free to the people who own them.

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners