caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: "Luca de Alfaro" <luca@dealfaro.org>
To: "David Teller" <David.Teller@ens-lyon.org>
Cc: "Zheng Li" <li@pps.jussieu.fr>, caml-list@inria.fr
Subject: Re: [Caml-list] Re: Why can't I call a function over a subclass?
Date: Fri, 5 Oct 2007 08:12:12 -0700	[thread overview]
Message-ID: <28fa90930710050812i204e975ap847e7474ec9580bc@mail.gmail.com> (raw)
In-Reply-To: <28fa90930710050759m682d8b65g72a31cc311acc276@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 2696 bytes --]

I am sorry - I am wrong.  I get an error in both cases listed below.
So the behavior is disconcerting to me, and no clear elegant solution
exists, but at least the behavior is consistent.

Luca

On 10/5/07, Luca de Alfaro <luca@dealfaro.org> wrote:
>
> The problem is also that the example I posted is a minimal instance of the
> problem, but my real problem is much harder to solve (or so I believe, let
> me know if you have suggestions!).
> My real problem is that I have a class r, that internally, in many places,
> uses objects of a class p.
> Then I subclass r into r', and in r', I need to replace objects of type p
> with objects of type p', a subclass of p.
> Inside r I have a method do_work that does something like, in its body:
>
>  ...
> let x = new Pclass.p in
> ...
>
> Now, if I cut-and-paste the code of do_work from r to r', and change the
> above line in:
> let x = new Pclass.p' in
> then everything works.
> If instead I replace the code in r with:
>
> method make_p = new Pclass.p
>
> ...
> let x = make_p in
> ...
>
> so that in r', I just need to override make_p with:
>
> method make_p = new Pclass.p'
>
> then the code does not type check --- and I don't know why, and in any
> case it is not logical to me.
> What would be the solution in this case?  The classes p, p' are used in
> many places in r, r', but the error only occurs when I do the above change.
> Any help would be appreciated --- at least, so that I understand better
> how not to break my code...
>
> Luca
>
>
> On 10/5/07, David Teller <David.Teller@ens-lyon.org> wrote:
> >
> > Sure. I'm just saying that this default behaviour is disconcerting.
> >
> > In addition to which, while it does appear in the documentation, it's
> > rather well hidden inside section 3.11 "Polymorphic methods" -- even
> > though this is not a method.
> >
> > Cheers,
> > David
> >
> > On Fri, 2007-10-05 at 12:53 +0200, Zheng Li wrote:
> > > David Teller <David.Teller@ens-lyon.org> writes:
> > > > I agree with Luca that it's disconcerting.
> > > > When r is a class, I would expect
> > >
> > > >  let f (x:r) (y:r) =...
> > > This expression says f accept arguments of type [r], what you mean to
> > say is: f
> > > accept any arguments belong to [r]'s subtypes family. Then say it with
> > >
> > > # let f (x:#r) (y:#r) = x#get_x = y#get_x
> > > val f : #r -> #r -> bool = <fun>
> > >
> >
> > _______________________________________________
> > Caml-list mailing list. Subscription management:
> > http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
> > Archives: http://caml.inria.fr
> > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> > Bug reports: http://caml.inria.fr/bin/caml-bugs
> >
>
>

[-- Attachment #2: Type: text/html, Size: 4296 bytes --]

  reply	other threads:[~2007-10-05 15:12 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-10-05  7:48 Luca de Alfaro
2007-10-05  8:01 ` [Caml-list] " Florian Hars
2007-10-05  8:08   ` Luca de Alfaro
2007-10-05  8:08     ` Fwd: " Luca de Alfaro
2007-10-05 11:08     ` Vincent Aravantinos
2007-10-05 11:47       ` Christophe Raffalli
2007-10-05 10:30   ` David Teller
2007-10-05 10:53     ` Zheng Li
2007-10-05 14:02       ` [Caml-list] " David Teller
2007-10-05 14:59         ` Luca de Alfaro
2007-10-05 15:12           ` Luca de Alfaro [this message]
     [not found]             ` <20071005152130.M41697@cs.unm.edu>
2007-10-05 15:49               ` Luca de Alfaro
2007-10-05 16:34                 ` Edgar Friendly
2007-10-05 17:39                   ` Luca de Alfaro
2007-10-05 17:49                     ` Martin Jambon
     [not found]                       ` <28fa90930710052153k2128bb63m5132455868eb2008@mail.gmail.com>
2007-10-07 22:19                         ` Martin Jambon
2007-10-07 22:57                         ` Classes and polymorphism (Re: [Caml-list] Re: Why can't I call a function over a subclass?) Martin Jambon
2007-10-05 19:48                 ` Why can't I call a function over a subclass? Zheng Li
2007-10-06  1:49                   ` [Caml-list] " Jake Donham
2007-10-09  4:18                 ` Jacques Garrigue
2007-10-05  8:07 ` [Caml-list] " Pietro Abate
2007-10-05 10:55 ` Andrej Bauer

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=28fa90930710050812i204e975ap847e7474ec9580bc@mail.gmail.com \
    --to=luca@dealfaro.org \
    --cc=David.Teller@ens-lyon.org \
    --cc=caml-list@inria.fr \
    --cc=li@pps.jussieu.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).