Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Jacques GARRIGUE <garrigue@math.nagoya-u.ac.jp>
To: oliver@first.in-berlin.de
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Type notation in OO-layer
Date: Sat, 04 Aug 2007 09:38:42 +0900 (JST)	[thread overview]
Message-ID: <20070804.093842.2004166723.garrigue@math.nagoya-u.ac.jp> (raw)
In-Reply-To: <1186176540.46b39e1c6f460@webmail.in-berlin.de>

From: Oliver Bandel <oliver@first.in-berlin.de>
> Zitat von Oliver Bandel <oliver@first.in-berlin.de>:
> 
> [...]
> > As it is not a true "unit"-function, we at least should give it a
> > unit-like type like "message -> string" so that the type-system
> > make a complete annotation of type?!
> 
> 
> OK, I had misleading thoughts here: not the method get's the message,
> the object gets the message.
> 
> So, the type of the function is OK.
> But shouldn't the message be somewhere else notated?
> 
> Or is this thrown out in general, when using OO?
> 
> I sthere no contradiction, when using such a type annotation,
> when comparing it to the non-OO stuff?

The object-oriented view that objects "understand" messages is somewhat
confusing, because it makes unclear where the code is. More directly,
a method call is decoded as:

   obj#meth == obj.meth obj

So, as you have correctly noted, since any method is getting the object
itself as argument, any method call contains a function application,
and the value it returns need not be always the same.
However, this may also be confusing and/or not practical at times.
For instance, what is the meaning of a method of type only "unit" ?

The approach used in lablgtk for instance is to have all
side-effecting methods take at least one argument. Taking unit as an
argument is useful at times, for instance if you want to use it as a
callback (i.e. if you want to make a closure of a method call).
On the other hand, accessors to mutable values do not take unit as
argument. This reflects the fact we use the same syntax for both
mutable and immutable fields in records.
While I think this distinction between side-effecting and non
side-effecting methods is useful, there is no way to have the language
verify it (you would have to know it for functions too...), and some
people might not like the extra argument, so this is difficult to make
it a hard rule.

Jacques Garrigue


  reply	other threads:[~2007-08-04  0:39 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-08-03 21:18 Oliver Bandel
2007-08-03 21:29 ` [Caml-list] " Oliver Bandel
2007-08-04  0:38   ` Jacques GARRIGUE [this message]
2007-08-04  3:28 ` Julien Moutinho

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=20070804.093842.2004166723.garrigue@math.nagoya-u.ac.jp \
    --to=garrigue@math.nagoya-u.ac.jp \
    --cc=caml-list@inria.fr \
    --cc=oliver@first.in-berlin.de \
    /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