caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: brogoff <brogoff@speakeasy.net>
To: Jacques Garrigue <garrigue@math.nagoya-u.ac.jp>
Cc: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] Polymorphic method question
Date: Tue, 11 Jul 2006 11:20:32 -0700 (PDT)	[thread overview]
Message-ID: <Pine.LNX.4.58.0607111016200.30637@shell2.speakeasy.net> (raw)
In-Reply-To: <20060711.163207.72458365.garrigue@math.nagoya-u.ac.jp>

On Tue, 11 Jul 2006, Jacques Garrigue wrote:
> From: brogoff <brogoff@speakeasy.net>
> > > By the way, if you're ready to define your types first, then you
> > > can do this properly.
> >
> > In the more realistic example I sent along after, you'll see that this
> > solution is not really pleasing. You'd need to create a parallel type
> > hierarchy to match your class hierarchy, which is too verbose. All this
> > because we must have inference, which is supposed to make things less
> > verbose. Ironic, isn't it? ;-)
>
> I'm not so sure about verbosity. Type syntax is pretty compact :-)

But we have to repeat the information from the type in a later class,
which seems redundant. Also, there's no way I know of to build object types
from other object types, similar to the way I can combine polymorphic variant
types.

I haven't tried to encode it yet, maybe I'll try later, but I don't see how it
can be made to work.

> I'm sure you need some tricks to make it work in Java 1.5 too.

The nastiest one for Caml is a downcast, when you want to extend the data
the new class must call the extended visitor in its visit method. But Java
supports this, so no big deal. Also, Java generics require that primitive
types be wrapped, a mild annoyance. That's about it. Way easier than my
attempts in OCaml, even though I don't use Java much at all. OK, to be fair,
the original paper uses some Java variant (Pizza?) so maybe that's not too
surprising. I wrote the code and it compiled, but I haven't tested it.

> I don't have the code in mind.
> I agree that the solution I posted is not too simple, but I don't
> think this is PhD level. Actually it's not much worse than the visitor
> pattern. What is hard is understanding why you have to do all this
> extra work, not using the pattern itself.

Sure, I exaggerated for affect, but I think the comparison with Java for this
problem is telling.

I'm reminded of something David MacQueen wrote in his paper "Should ML be
Object Oriented" where he says in essence that the functional core of ML
is lightweight and understandable but that OO (from the static typing POV)
is surprisingly subtle and complex.

> Note that, if you are ready to use a slightly less functional
> approach, where the result is extracted from the visitor afterwards,
> then typing is no problem.
> This code is based on http://cristal.inria.fr/~remy/work/expr/
> It is strictly equivalent to Odersky&Zenger's Scala version.
> (Actually this kind of code is one reason we reverted to sharing of
> instance variables in 3.10)

That's probably the right way to proceed, namely to eliminate the
problem by eliminating the polymorphic methods. Too bad, the Java
solution is both more functional, and more "typed". One of those
rare cases for me where I feel that the Java solution is more
elegant than the OCaml one.

-- Brian


  reply	other threads:[~2006-07-11 18:20 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-07-10 19:21 brogoff
2006-07-10 20:05 ` [Caml-list] " Richard Jones
2006-07-10 23:25   ` brogoff
2006-07-11  2:24     ` skaller
2006-07-11  4:56       ` brogoff
2006-07-11  2:09 ` Jacques Garrigue
2006-07-11  5:22   ` brogoff
2006-07-11  7:32     ` Jacques Garrigue
2006-07-11 18:20       ` brogoff [this message]
2006-07-12  0:37         ` Jacques Garrigue
2006-07-12 19:26           ` brogoff
  -- strict thread matches above, loose matches on Subject: below --
2002-08-21 21:49 [Caml-list] polymorphic " nadji
2002-08-21 22:57 ` Jacques Garrigue

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.0607111016200.30637@shell2.speakeasy.net \
    --to=brogoff@speakeasy.net \
    --cc=caml-list@yquem.inria.fr \
    --cc=garrigue@math.nagoya-u.ac.jp \
    /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).