caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Xavier Leroy <Xavier.Leroy@inria.fr>
To: Mark Engelberg <mark.engelberg@bigfoot.com>, caml-list@inria.fr
Subject: Re: Classes AND Modules?  What's the point?
Date: Fri, 5 Nov 1999 11:13:34 +0100	[thread overview]
Message-ID: <19991105111334.48749@pauillac.inria.fr> (raw)
In-Reply-To: <00fb01bf2447$9ef382a0$03dedede@walldata.com>; from Mark Engelberg on Mon, Nov 01, 1999 at 01:01:00AM -0800

> I have spent some time this past week looking at OCaml for the first time.
> I have no previous experience with ML, but I do have a pretty good
> understanding of functional languages in principle.
> The thing that confuses me the most about OCaml is that there is a huge
> overlap between the functionality of classes and modules, with a couple of
> subtle differences.  Classes offer inheritance which is extremely useful,
> but modules have a little more typing flexibility, the ability to share
> private data among multiple structures in one package, and the ability to
> specify compilation units.

We are aware of the overlap between classes and modules, although I'm
not sure the overlap is as large as you say.  I gave an invited talk
on this topic at last ICFP; the slides are available from my home page
(http://pauillac.inria.fr/~xleroy/)

> The problem is that because modules are slightly more powerful, it appears
> that the entire standard library is implemented as modules, not classes,
> despite the fact that this is supposed to be Object-oriented Caml!

There are two reasons why the standard library is implemented without
classes.  The historical reason is that the standard library comes
straight from Caml Special Light, the ancestor of OCaml that didn't
have classes and objects yet, but already had objects.

The other reason is that I don't see any module in the standard
library (except perhaps Format) that would really benefit from being
converted into objects and classes.  For many data structures
(hash tables, stacks, etc) the class-based presentation would be no
better than the current module/abstract data type presentation.
For others (sets, maps), the class-based presentation would be less
good, e.g. with less precise static typing.

> This
> doesn't really make sense to me, because it totally hinders your ability to
> subclass and extend the default libraries.

Do you really need to?  What good would it make to subclass hash
tables as opposed to putting a hash table in a field or instance
variable of another datatype or class?  No offense intended, but
programmers with extensive C++/Java background are so used to the
inheritance hammer that they see every problem as a nail.  Inheritance
is great in some cases (I've used it in parts of the native-code
compiler and it was very nice), but in my opinion nearly useless for
simple data structures like those of the OCaml standard library.

> This weird coexistence of classes and modules just doesn't make sense to me.
> Wouldn't it have made more sense to simply add the concept of inheritance to
> modules, rather than define a new "class" construct that supports
> inheritance but not all the other features of modules?

It would make a lot of sense, but it's still an open research issue.
In particular, no-one knows yet how to "add the concept of inheritance
to modules" in a way that really reduces the overlap between classes and
modules.  (See for instance Jérôme Vouillon's paper "Using modules as
classes", http://pauillac.inria.fr/~vouillon/publi/classes.ps.gz)

> Or if the focus is
> intended to gradually shift in the direction of classes rather than modules,
> shouldn't the standard libraries reflect this?

My intention is certainly not to shift away from modules.  The way I
like to think about OCaml is that you have functions, datatypes and
modules for "everyday" programming, and classes and objects for those
programs that need them in an essential way.

- Xavier Leroy



  parent reply	other threads:[~1999-11-05 17:53 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-11-01  9:01 Mark Engelberg
1999-11-03 23:13 ` William Chesters
1999-11-05 10:13 ` Xavier Leroy [this message]
1999-11-05 18:49 ` Francisco Valverde Albacete
1999-11-07 23:31   ` Gerd Stolpmann

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=19991105111334.48749@pauillac.inria.fr \
    --to=xavier.leroy@inria.fr \
    --cc=caml-list@inria.fr \
    --cc=mark.engelberg@bigfoot.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;
as well as URLs for NNTP newsgroup(s).