From: james woodyatt <jhw@wetware.com>
To: Jacques Garrigue <garrigue@kurims.kyoto-u.ac.jp>
Cc: The Trade <caml-list@inria.fr>
Subject: Re: [Caml-list] Oo.id
Date: Fri, 4 Oct 2002 09:52:59 -0700 [thread overview]
Message-ID: <BD3D6DB5-D7B9-11D6-AC8C-000393BA7EBA@wetware.com> (raw)
In-Reply-To: <20021004165824H.garrigue@kurims.kyoto-u.ac.jp>
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
next prev parent reply other threads:[~2002-10-04 16:53 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-10-04 0:43 james woodyatt
2002-10-04 7:58 ` Jacques Garrigue
2002-10-04 16:52 ` james woodyatt [this message]
2002-10-08 19:46 ` Lauri Alanko
2002-10-10 0:52 ` Jacques Garrigue
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=BD3D6DB5-D7B9-11D6-AC8C-000393BA7EBA@wetware.com \
--to=jhw@wetware.com \
--cc=caml-list@inria.fr \
--cc=garrigue@kurims.kyoto-u.ac.jp \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox