caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Fergus Henderson <fjh@cs.mu.OZ.AU>
To: Jean-Marc Alliot <alliot@recherche.enac.fr>
Cc: caml-list@inria.fr
Subject: Re: Overloading again (Was Re: [Caml-list] Interfacing C++ and Ocaml)
Date: Mon, 2 Apr 2001 23:48:08 +1000	[thread overview]
Message-ID: <20010402234808.A8780@murlibobo.cs.mu.OZ.AU> (raw)
In-Reply-To: <3AC834B4.559806D0@recherche.enac.fr>; from Jean-Marc Alliot on Mon, Apr 02, 2001 at 10:13:40AM +0200

On 02-Apr-2001, Jean-Marc Alliot <alliot@recherche.enac.fr> wrote:
> Well, I am going to be the black sheep again, but as an old ADA and C++
> programmer, I don't really want to see overloading pop up in ML.

Incidentally, it's "Ada", not "ADA".

> Overloading can become easily a source of mistakes. My favorite example
> is the following. A few years ago, I was managing a project with C++
> code, and one of the programmer was using a third party library (the
> author of this library was gone and had been replaced). And he had a
> bug inside the following code fragment in that library:
>
> toto(titi *initp)
> {
> titi *p;
> 
> for (p=initp;p!=NULL;p++)
>    {
>      .......
>    }
> 
> }
> 
> And it took him a very long time to realize that the ++ operator had
> been overloaded, somewhere in a .h file included in an other .h file,
> and that instead of incrmenting the pointer, it was doing something
> like p=p->next, with a next field incorrectly initialized somewhere.

This example is a bogus example, since C++ doesn't allow that kind of
overloading.  C++ requires that every overloaded operator have at least
one parameter whose type is a class, or a reference to a class,
an enumeration, or a reference to an enumeration (see e.g. 13.1.1.2
in the C++ standard).  In this case the argument has pointer type,
so it can't call an overloaded operator.

My opinion with regard to overloading is that what is really
problematic about overloading in C++ is the *combination* of
overloading and implicit conversions.

Mercury supports overloading, without implicit conversions,
in my experience it works fine.  The main drawbacks are that
(a) occaisionally you need to use explicit type annotations
to resolve ambiguities and (b) sometimes the presence of overloading
makes it harder for the type checker to issue good error messages.

-- 
Fergus Henderson <fjh@cs.mu.oz.au>  |  "I have always known that the pursuit
                                    |  of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh>  |     -- the last words of T. S. Garp.
-------------------
To unsubscribe, mail caml-list-request@inria.fr.  Archives: http://caml.inria.fr


  reply	other threads:[~2001-04-02 13:48 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-03-30  8:54 [Caml-list] Interfacing C++ and Ocaml David Chemouil
2001-03-30  9:13 ` Bruce Hoult
2001-03-30  9:24   ` Fergus Henderson
2001-03-30 16:50 ` Overloading again (Was Re: [Caml-list] Interfacing C++ and Ocaml) Brian Rogoff
2001-04-02  8:13   ` Jean-Marc Alliot
2001-04-02 13:48     ` Fergus Henderson [this message]
2001-04-02 14:30       ` Jean-Marc Alliot
2001-04-02 15:49         ` Brian Rogoff
2001-04-09  6:47           ` John Max Skaller
2001-04-02 15:51     ` Brock
2001-03-30 20:41 Hao-yang Wang
2001-04-01 20:15 ` Sven LUTHER
2001-04-02 11:07   ` Sven LUTHER

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=20010402234808.A8780@murlibobo.cs.mu.OZ.AU \
    --to=fjh@cs.mu.oz.au \
    --cc=alliot@recherche.enac.fr \
    --cc=caml-list@inria.fr \
    /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).