From: Jacques Garrigue <garrigue@kurims.kyoto-u.ac.jp>
To: ben@socialtools.net
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] does class polymorphism need to be so complicated?
Date: Thu, 21 Aug 2003 17:58:08 +0900 [thread overview]
Message-ID: <20030821175808V.garrigue@kurims.kyoto-u.ac.jp> (raw)
In-Reply-To: <3F448015.8090106@socialtools.net>
From: Benjamin Geer <ben@socialtools.net>
> > To speak truly, the current syntax is based on the assumption that you
> > won't define often polymorphic methods, and that defining them is a
> > work for library designers, not for the average end user.
>
> I think that one of the things that would improve life a great deal, for
> people wanting to write applications in Caml, would be the existence of
> many more libraries. Unfortunately, I think languages become popular
> not mainly because of how expressive they are, but because of the
> libraries available in them. Therefore, in order to help Caml become
> more widely used, it would be a good idea to make things as easy as
> possible for library authors.
Sure.
There's no intent to make it difficult.
The idea is only that being a bit more verbose on a declaration that
is hopefully made only once in a hierarchy is not that bad.
The real problem actually is not verbosity, but the fact you have to
understand that there can be two levels for polymorphism: the class or
the method. I think that's not that immediate, and I don't want to
bother beginners with that. We'll see the impact on Java programmers
when they will get generics.
> Moreover, a library user needs to handle the library's own polymorphism.
> For example, suppose there were a Caml API for accessing databases,
> and that this API consisted entirely of class types, intended to be
> implemented by Caml 'drivers' for different databases. The library user
> would get a #connection; the class implementing #connection would be
> determined by the driver (and would never be known by the library user).
> In this way, the user could switch to a different database by
> switching to a different driver, without having to change any
> application code. In order to pass around this #connection object
> within the application, the library user would have to write polymorphic
> methods.
Here there may be a deeper misunderstanding about the ocaml type
system: if a subclass does not add methods to its superclass, its type
does not change.
That is, I would expect all connections to have the same type, and as
a result there is no need for considering the more general
#connection.
> > This also means that you have a number of workarounds hiding this
> > heavy syntax to the end user, even when he has to define such a
> > method.
> >
> > For instance you could be provided a virtual class printer:
> >
> > class virtual printer : object
> > method virtual print : #printable -> unit
> > method ...
> > end
> >
> > Then you would use it as
> >
> > class my_printer () = object
> > inherit printer
> > method print obj = ...
> > end
>
> That's somewhat better, but it means that every class must be derived
> from a virtual base, even when there's no other reason for it.
OK, there's also another way to do it, without inheritance. I just
tried not to be confusing.
class type printer = object
method virtual print : #printable -> unit
end
class my_printer () = object (self : #printer)
method print obj = ...
end
Looks a bit strange at first, but it does the work.
> > P.S. Having a lighter syntax for polymorphic methods might be a good
> > idea. But since we must keep it explicit enough, the improvement would
> > be quite limited. The best I can think of is something like:
> > method 'a. print (obj : #printable as 'a) = ...
> > Maybe a bit better, but also more complicated to handle.
>
> I think that would definitely be an improvement.
Might consider it. But its a rather big change in the language, so
this requires some more study.
Jacques
-------------------
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
next prev parent reply other threads:[~2003-08-21 8:58 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-08-20 15:42 Benjamin Geer
2003-08-20 16:05 ` Brian Hurt
2003-08-20 16:19 ` Richard Jones
2003-08-20 16:25 ` Benjamin Geer
2003-08-20 17:09 ` brogoff
2003-08-20 17:25 ` Jacques Carette
2003-08-20 23:34 ` Jacques Garrigue
2003-08-21 13:27 ` Jacques Carette
2003-08-20 18:19 ` Benjamin Geer
2003-08-20 20:39 ` brogoff
2003-08-20 21:04 ` Benjamin Geer
2003-08-21 0:28 ` Jacques Garrigue
2003-08-21 8:17 ` Benjamin Geer
2003-08-21 8:58 ` Jacques Garrigue [this message]
2003-08-21 9:38 ` Benjamin Geer
2003-08-21 11:44 ` Remi Vanicat
2003-08-21 13:11 ` Richard Jones
2003-08-21 16:41 ` Remi Vanicat
2003-08-21 18:04 ` brogoff
2003-08-21 20:20 ` Benjamin Geer
2003-08-21 23:35 ` Benjamin Geer
2003-08-22 3:59 ` Jacques Garrigue
2003-08-22 7:12 ` Benjamin Geer
2003-08-21 13:38 ` Benjamin Geer
2003-08-21 0:58 ` brogoff
2003-08-20 23:40 ` Benjamin Geer
2003-08-21 1:29 ` Jacques Garrigue
2003-08-21 9:19 ` Benjamin Geer
2003-08-21 18:44 ` Chris Clearwater
2003-08-20 20:43 ` Issac Trotts
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=20030821175808V.garrigue@kurims.kyoto-u.ac.jp \
--to=garrigue@kurims.kyoto-u.ac.jp \
--cc=ben@socialtools.net \
--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).