caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Damien <Damien.Pous@ens-lyon.fr>
Cc: caml-list@pauillac.inria.fr
Subject: Re: [Caml-list] polymorphic methods
Date: Thu, 13 Mar 2003 15:49:29 +0100	[thread overview]
Message-ID: <20030313154929.51f68b16.Damien.Pous@ens-lyon.fr> (raw)
In-Reply-To: <20030313182702L.garrigue@kurims.kyoto-u.ac.jp>

On Thu, 13 Mar 2003 18:27:02 +0900
Jacques Garrigue <garrigue@kurims.kyoto-u.ac.jp> wrote:


> > but that's not really a beautiful piece of code !
> And I would not have expected it to be!
> This was just a theoretical answer.
:-)

> If you are bothered by coercions, you may have a look at the trick in
> lablgtk, which avoids polymorphic methods: give the parent as
> argument.
> let new_node ?parent () =
>   let n = new node in
>   begin match parent with None -> ()
>   | Some (p : #a_t) -> p#add (n :> a_t)
>   end;
>   n
> You can also do the trick in an initializer.
That's what I planned to do, but my trees are 'dynamic', i.e. I need to
move nodes across the tree, so an initializer is not sufficient ...
-> I'll use some helper function, or the tricks that have been proposed


> Alternatively, you might just have an interface of a_t without
> the method m. This way you have no problem with recursion:
> 
> class type a0_t = object
>   ... everything but add ...
> end
> class type a_t = object
>   inherit a0_t
>   method add : #a0_t -> unit
> end
But then, when I retrieve a child from its parent, it has no more add
capability :-(


> > I don't know what do you mean when saying 
> > "such a type cannot be defined", in fact, I could define this 
> > equivalent (I think it is...) :
> > 
> > >#class type a_t = object 
> > >   method m: 'a.(<m: 'a -> unit; ..> as 'a) -> unit 
> > >end 
> 
> This is not equivalent: the m in a_t is a polymorphic method, but not
> the one in the recursion. Polymorphic and monomorphic methods are
> incompatible, so you cannot pass an a_t to m.
thanks for the explanation !


Now, questions :
Would it be useful to accept such a type (not just for my trees) ?
Would it be correct (semantically) ?

You told about "a way to recurse on a quantified polymorphic method
rather than on the whole object." (that does not exists), 
Would it be useful (and correct) ? Has someone studied this ?

damien

-------------------
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:[~2003-03-13 14:52 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-03-12 23:07 Damien
2003-03-13  0:56 ` brogoff
2003-03-13  1:56 ` Jacques Garrigue
2003-03-13  9:04   ` Damien
2003-03-13  9:27     ` Jacques Garrigue
2003-03-13 14:49       ` Damien [this message]
2003-03-13  9:41     ` Olivier Andrieu
  -- strict thread matches above, loose matches on Subject: below --
2015-12-18  9:18 Christoph Höger
2015-12-18 10:07 ` Leo White
2002-08-23 15:46 [Caml-list] Polymorphic methods Frederic Tronel
2002-08-23 17:32 ` Fred Smith
2002-08-23 18:21 ` Remi VANICAT
2002-07-14 23:16 [Caml-list] polymorphic methods nadji
2002-07-15  1:05 ` Jacques Garrigue
2002-07-15  2:08   ` Brian Smith
2002-07-15 16:24   ` nadji
2001-11-19 15:29 [Caml-list] Polymorphic methods Alain Frisch
2001-11-20  0:29 ` Jacques Garrigue
2001-11-20  9:33   ` Alain Frisch
2001-11-20 20:55   ` Xavier Leroy

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=20030313154929.51f68b16.Damien.Pous@ens-lyon.fr \
    --to=damien.pous@ens-lyon.fr \
    --cc=caml-list@pauillac.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).