caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Oo.id
@ 2002-10-04  0:43 james woodyatt
  2002-10-04  7:58 ` Jacques Garrigue
  0 siblings, 1 reply; 5+ messages in thread
From: james woodyatt @ 2002-10-04  0:43 UTC (permalink / raw)
  To: The Trade

everyone--

No one answered my question the first time, and I'm still curious.  
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?


-- 
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


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Caml-list] Oo.id
  2002-10-04  0:43 [Caml-list] Oo.id james woodyatt
@ 2002-10-04  7:58 ` Jacques Garrigue
  2002-10-04 16:52   ` james woodyatt
  2002-10-08 19:46   ` Lauri Alanko
  0 siblings, 2 replies; 5+ messages in thread
From: Jacques Garrigue @ 2002-10-04  7:58 UTC (permalink / raw)
  To: jhw; +Cc: caml-list

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?

Since objects contain a method table, which is composed of closures,
using standard comparison functions on them would be unsafe. In
practice this was even worse as this worked somehow, but only part of
the time :-(
Using the address would be ok for equality, but not for compare, as
the GC may move things around: the result of compare might change.

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.

        Jacques Garrigue
-------------------
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


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Caml-list] Oo.id
  2002-10-04  7:58 ` Jacques Garrigue
@ 2002-10-04 16:52   ` james woodyatt
  2002-10-08 19:46   ` Lauri Alanko
  1 sibling, 0 replies; 5+ messages in thread
From: james woodyatt @ 2002-10-04 16:52 UTC (permalink / raw)
  To: Jacques Garrigue; +Cc: The Trade

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


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Caml-list] Oo.id
  2002-10-04  7:58 ` Jacques Garrigue
  2002-10-04 16:52   ` james woodyatt
@ 2002-10-08 19:46   ` Lauri Alanko
  2002-10-10  0:52     ` Jacques Garrigue
  1 sibling, 1 reply; 5+ messages in thread
From: Lauri Alanko @ 2002-10-08 19:46 UTC (permalink / raw)
  To: caml-list

On Fri, Oct 04, 2002 at 04:58:24PM +0900, Jacques Garrigue wrote:
> Using the address would be ok for equality, but not for compare, as
> the GC may move things around: the result of compare might change.

Why does there need to be an ordering for objects in the first place?
This seems about as sensible as ordering closures (ie. not very).

Alternatively, if the stability of addresses is important, couldn't
objects be allocated in a special heap where GC would be non-copying?


Lauri Alanko
la@iki.fi
-------------------
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


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Caml-list] Oo.id
  2002-10-08 19:46   ` Lauri Alanko
@ 2002-10-10  0:52     ` Jacques Garrigue
  0 siblings, 0 replies; 5+ messages in thread
From: Jacques Garrigue @ 2002-10-10  0:52 UTC (permalink / raw)
  To: la; +Cc: caml-list

From: Lauri Alanko <la@iki.fi>
> On Fri, Oct 04, 2002 at 04:58:24PM +0900, Jacques Garrigue wrote:
> > Using the address would be ok for equality, but not for compare, as
> > the GC may move things around: the result of compare might change.
> 
> Why does there need to be an ordering for objects in the first place?
> This seems about as sensible as ordering closures (ie. not very).

Because objects have identity and data contents, which closure don't
have. You need the ordering for functors like Map or Set, and it has
to be an int for Hashtbl.

> Alternatively, if the stability of addresses is important, couldn't
> objects be allocated in a special heap where GC would be non-copying?

You might want stability of addresses for all mutable data structures,
but this would also mean a much less eficient GC. As Caml is a
functional language, GC speed is favored over a strong definition of
physical ordering. You just have to add an id when you need it, which
is not really difficult. Strictly speaking, the id could be delegated
to users for objects too, but having it buitin avoids trouble with
beginners.

   Jacques Garrigue
-------------------
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


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2002-10-10  0:53 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-10-04  0:43 [Caml-list] Oo.id james woodyatt
2002-10-04  7:58 ` Jacques Garrigue
2002-10-04 16:52   ` james woodyatt
2002-10-08 19:46   ` Lauri Alanko
2002-10-10  0:52     ` Jacques Garrigue

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).