From: Tom <tom.primozic@gmail.com>
To: "Joel Reymont" <joelr1@gmail.com>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Instruction selection in the OCaml compiler: Modules or classes?
Date: Thu, 22 Feb 2007 18:21:13 +0100 [thread overview]
Message-ID: <c1490a380702220921o7b522d44r5eeae6f258660487@mail.gmail.com> (raw)
In-Reply-To: <6CB0D237-F894-4AC3-BDBE-2BB484928D3C@gmail.com>
[-- Attachment #1: Type: text/plain, Size: 922 bytes --]
Classes in OCaml are indeed slow, but that is because they are incredibly
different from modules. A class has fields, that is, meathods, that are
"named" and searched by comparing hashes. Modules also have fields,
functions and values, but they are named only as far as the programmer in
concerned - in compiled code, they are indexed (by an integer), and
actually, the native compiler can actually optimise even that (so only a
plain function call remains). In contrast, everytime you call a method of an
object, it is searched in the method list of that class (well, I think there
is some caching too).
But this "slowness" is expected - objects are also more adaptable than
modules. If you have a function
# let f o = o#some_method ();;
val f : < some_method : unit -> 'a; .. > -> 'a = <fun>
you can pass to it any object with method "some_method" of type unit -> 'a.
That's called structural subtyping.
- Tom
[-- Attachment #2: Type: text/html, Size: 1048 bytes --]
next prev parent reply other threads:[~2007-02-22 17:21 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-02-22 14:38 Joel Reymont
2007-02-22 17:21 ` Tom [this message]
2007-02-22 17:38 ` [Caml-list] " Xavier Leroy
2007-02-22 19:55 ` Chris King
2007-02-22 19:59 ` Markus Mottl
2007-02-23 16:13 ` brogoff
2007-02-23 18:14 ` Tom
2007-02-23 19:28 ` [Caml-list] Instruction selection in the OCaml compiler: Modulesor classes? Andreas Rossberg
2007-02-24 2:51 ` skaller
2007-02-24 11:48 ` David Baelde
[not found] ` <4a708d20702240518l2c430b06r18fe64cabe5cbe9@mail.gmail.com>
2007-02-24 13:33 ` Lukasz Stafiniak
2007-02-24 14:58 ` [Caml-list] Instruction selection in the OCaml compiler:Modulesor classes? Andreas Rossberg
2007-02-24 17:39 ` skaller
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=c1490a380702220921o7b522d44r5eeae6f258660487@mail.gmail.com \
--to=tom.primozic@gmail.com \
--cc=caml-list@inria.fr \
--cc=joelr1@gmail.com \
/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