caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Brian Hurt <bhurt@spnz.org>
To: "Marcin 'Qrczak' Kowalczyk" <qrczak@knm.org.pl>
Cc: caml-list <caml-list@inria.fr>
Subject: Re: [Caml-list] Re: OCAML Downcasting?
Date: Wed, 22 Sep 2004 14:18:45 -0500 (CDT)	[thread overview]
Message-ID: <Pine.LNX.4.44.0409221358230.5809-100000@localhost.localdomain> (raw)
In-Reply-To: <87fz5axhwe.fsf@qrnik.zagroda>

On Wed, 22 Sep 2004, Marcin 'Qrczak' Kowalczyk wrote:

> Brian Hurt <bhurt@spnz.org> writes:
> 
> >> Apply this reasoning to the exn type. Why don't you define all exn
> >> constructors in one place?
> >
> > Ignoring the fact that exceptions are built into the language, I'd read
> > section 4.2 "Polymorphic Variants" of the Ocaml language manual for how to
> > get around this.
> 
> It helps only in some cases. In particular it's not expressive enough
> to replace exn.

No.  That's why exceptions were built into the language.

It does, however, allow you to 'retrofit' RTTI onto any type:

let do_stuff = function
    | `Foo of foo ->
        (* our argument is only of type foo, only do stuff we can
           do with a foo.
         *)
        foo#do_foo_stuff()
    | `Bar of bar ->
        (* In addition to being a foo, our argument is also a bar.
           Do foo stuff and bar stuff.
         *)
        bar#do_foo_stuff ();
        bar#do_bar_stuff ()
;;

As for interpreting a RTTI language, I do a full on interpreter.  I don't
try to use Ocaml as an intermediate language.  Every object gets a
StringMap ( = Map.Make(String)) to allow me to look up the member function
definition from the function name.  I collect the arguments up into
another StringMap (mapping from the name of the argument to the value),
and pass that it to any function I call.  Yes, you have to add the type 
information to every object, instead of having the compiler do it for you.

There is a whole long list of features Ocaml has that Java lacks, or 
requires you to use broken kludges to work around.  It sounds like- the 
better part of a decade later- they finally figured out that univeral 
types and being able to express types like 'int array list list' is a good 
thing.  Partial function application still has to be kludged with "doit" 
objects- objects and interfaces with single member functions- the "doit" 
function.  And so on, and so forth.  

The trick is, when programming in Java, to "think in Java", not in Ocaml
(or C).  Likewise, the trick is, when programming in Ocaml, to think in
Ocaml.  The question is not "how do I make this particular Java solution
to the problem work?"  The question is "how do I solve this problem in
Ocaml?"

-- 
"Usenet is like a herd of performing elephants with diarrhea -- massive,
difficult to redirect, awe-inspiring, entertaining, and a source of
mind-boggling amounts of excrement when you least expect it."
                                - Gene Spafford 
Brian

-------------------
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


  reply	other threads:[~2004-09-22 19:08 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <ci7tcf$qqf$1@wolfberry.srv.cs.cmu.edu>
     [not found] ` <ci9ggm$i6p$1@wolfberry.srv.cs.cmu.edu>
2004-09-21  8:03   ` Jacques GARRIGUE
2004-09-21  8:43     ` Damien Pous
2004-09-21  9:15       ` Jacques GARRIGUE
2004-09-21  9:29         ` skaller
2004-09-21  9:49           ` Jacques GARRIGUE
2004-09-21  9:34         ` Stefano Zacchiroli
2004-09-21  9:56           ` Jacques GARRIGUE
2004-09-21 19:27     ` Michael Vanier
2004-09-21 21:38       ` Brian Hurt
2004-09-21 22:06         ` Michael Vanier
2004-09-21 22:32           ` Brian Hurt
2004-09-22  1:04           ` skaller
2004-09-21 22:20         ` Marcin 'Qrczak' Kowalczyk
2004-09-22  2:26           ` skaller
2004-09-22  6:31             ` Marcin 'Qrczak' Kowalczyk
2004-09-22  9:03               ` sejourne_kevin
2004-09-22 10:29               ` Richard Jones
2004-09-22 18:39                 ` Brian Hurt
2004-09-22 10:50               ` skaller
2004-09-22 12:03               ` Alain Frisch
2004-09-22 12:50               ` Cláudio Valente
2004-09-22 13:15                 ` Marcin 'Qrczak' Kowalczyk
2004-09-22 15:50                   ` skaller
2004-09-22 18:42               ` Brian Hurt
2004-09-22 18:44                 ` Marcin 'Qrczak' Kowalczyk
2004-09-22 19:18                   ` Brian Hurt [this message]
2004-09-22  0:50         ` skaller
2004-09-22  1:30       ` Jacques GARRIGUE
2004-09-22  2:59         ` skaller

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.44.0409221358230.5809-100000@localhost.localdomain \
    --to=bhurt@spnz.org \
    --cc=caml-list@inria.fr \
    --cc=qrczak@knm.org.pl \
    /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).