From: brogoff <brogoff@speakeasy.net>
To: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] "OCaml gives you only monomorphic methods in classes."
Date: Tue, 8 Jan 2008 09:29:39 -0800 (PST) [thread overview]
Message-ID: <Pine.LNX.4.58.0801080904160.12705@shell2.speakeasy.net> (raw)
In-Reply-To: <200801080942.36566.jon@ffconsultancy.com>
On Tue, 8 Jan 2008, Jon Harrop wrote:
> On Tuesday 08 January 2008 02:30:31 Jacques Garrigue wrote:
> > From: Jon Harrop <jon@ffconsultancy.com>
> > > In what way must methods be monomorphic in OCaml classes?
> >
> > They don't. With the restriction that the types of polymorphic
> > methods cannot be inferred. There is also another subtle
> > limitation, that object are only allowed to have regular
> > types. As a result, one cannot write a polymorphic map method in
> > ocaml, but this is possible in Java 2 or Scala.
>
> This begs a question for me: have people used this functionality in their
> OCaml code?
I don't understand your question. How could we use this functionality in
our OCaml code if it doesn't exist? You must mean something else,
perhaps "do I use polymorphic methods in my OCaml code?". Not now. I
did when translating some purely functional data structures from
Okasaki's book to OCaml, then rewrote them using the higher
order polymorphism of record fields, which we got at the same time, a
workaround to the lack of polymorphic recursion in OCaml.
> I personally make virtually no use of OCaml's OOP capabilities at all but I
Very punny ;-)
> make a lot of use of polymorphic variants. In all but a few cases, objects
> seem to be very rarely used by other people in OCaml code. The only notable
> exceptions I can think of are LablGTK2 and PXP.
I use them when I have record field name clashes and I decide that this
aspect of OCaml records hinders rather than helps readability. It is an
interesting topic, certainly. Pattern matching is less useful on records
than variants (IMO of course) so the fact that we don't have it on
objects doesn't bother me all that much. But in my experience I need to
provide a lot more explicit typing when using the OOP features than I'm
used to, in order to get comprehensible error messages.
> > I'm quite sure that Martin Odersky is aware of this. I would rather
> > interpret his quote as meaning that you have to extend HM in a
> > non-trivial way to allow this.
If the original quote was accurate, then I think this is quite generous,
as it seemed the statement was 'OCaml doesn't have polymorphic methods,
period-end-of-story".
Scala does look very interesting though, and if I need to work in a JVM
environment I'll seriously consider using it.
-- Brian
next prev parent reply other threads:[~2008-01-08 17:29 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-12-28 23:37 Jon Harrop
2007-12-28 23:55 ` [Caml-list] " Gordon Henriksen
2007-12-29 0:27 ` Jon Harrop
2007-12-29 1:19 ` Gordon Henriksen
2007-12-29 1:30 ` Jon Harrop
2007-12-31 14:02 ` Kuba Ober
2007-12-29 4:31 ` Dylan William Hardison
2007-12-29 7:09 ` Jon Harrop
2007-12-29 6:30 ` brogoff
2007-12-29 7:11 ` Jon Harrop
2007-12-29 16:57 ` brogoff
2008-01-08 2:30 ` Jacques Garrigue
2008-01-08 9:42 ` Jon Harrop
2008-01-08 13:45 ` Peng Zang
2008-01-08 17:29 ` brogoff [this message]
2008-01-08 21:25 ` Paolo Donadeo
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=Pine.LNX.4.58.0801080904160.12705@shell2.speakeasy.net \
--to=brogoff@speakeasy.net \
--cc=caml-list@yquem.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