caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: james woodyatt <jhw@wetware.com>
To: John Prevost <visigoth@cs.cmu.edu>
Cc: Richard Nyberg <rnyberg@it.su.se>, caml-list@inria.fr
Subject: Re: [Caml-list] let or val in objects
Date: Mon, 1 Apr 2002 14:54:33 -0800	[thread overview]
Message-ID: <6ECAB092-45C3-11D6-8146-000502DB38F5@wetware.com> (raw)
In-Reply-To: <20020401042820.A74928@laurelin.dementia.org>

On Monday, April 1, 2002, at 01:28 AM, John Prevost wrote:
> On Sun, Mar 31, 2002 at 10:40:51PM +0200, Richard Nyberg wrote:
>> Hello, I'm a bit confused regarding let bindings and nonmutable vals in
>> objects. Are there any difference between the classes a and b? or are 
>> they
>> equivalent?
>>
>> Like this:
>>
>> class a fd =
>>  let is = in_channel_of_descr fd in object ... end
>>
>> class b fd =
>>  object val is = in_channel_of_descr fd ... end;;
>
> In the second case, "is" is a named value that's part of the 
> object--inheriting
> classes can access its value, and if it is mutable, change the value.
>
> In the first case, "is" is a variable in the closure of the methods in
> the object.  Inheriting classes may not access its value in any way, 
> including
> (of course) modifying it if it has a mutable component.

I was following this thread in the hopes that I might learn whether 
there is any difference (in space or time) between values hidden by 
class signature matching and values in the methods closure.

For example, I wanted to know if there is any substantial savings to be 
gained by choosing one of the following forms over the other:

	(* assume:
	   type t
	   val f: t -> unit
	*)

	(* 1 *)
	class foo (x : t) = object method bar = f x end

	(* 2 *)
	class type foo_t = object method bar: unit end
	class foo x : foo_t = object val x' = x method bar = f x' end

As far as I can tell, these two forms are semantically equivalent.

So, I looked to see if the compiler generates the same output code for 
each case.  Cursory examination of the output of ocamlopt -S on my Mac 
OS X unit seems to show that it does.

I suspect the second case is optimized into the first case.  Or 
something.


--
j h woodyatt <jhw@wetware.com>

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


  reply	other threads:[~2002-04-01 22:54 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-03-31 20:40 Richard Nyberg
2002-04-01  9:28 ` John Prevost
2002-04-01 22:54   ` james woodyatt [this message]
2002-04-02  4:08 ` Brian Rogoff

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=6ECAB092-45C3-11D6-8146-000502DB38F5@wetware.com \
    --to=jhw@wetware.com \
    --cc=caml-list@inria.fr \
    --cc=rnyberg@it.su.se \
    --cc=visigoth@cs.cmu.edu \
    /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;
as well as URLs for NNTP newsgroup(s).