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
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2002-10-04 (16:53)
From: james woodyatt <jhw@w...>
Subject: Re: [Caml-list]
On Friday, Oct 4, 2002, at 00:58 US/Pacific, Jacques Garrigue wrote:
> From: james woodyatt <>
>> 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 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 <>
markets are only free to the people who own them.

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