From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.2 required=5.0 tests=AWL,HTML_MESSAGE autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by yquem.inria.fr (Postfix) with ESMTP id 801ACBC69 for ; Fri, 5 Oct 2007 17:12:16 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAAKfwBUfAXQInh2dsb2JhbACCPTSLSAIBCAop X-IronPort-AV: E=Sophos;i="4.21,236,1188770400"; d="scan'208";a="2192036" Received: from concorde.inria.fr ([192.93.2.39]) by mail1-smtp-roc.national.inria.fr with ESMTP; 05 Oct 2007 17:12:15 +0200 Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by concorde.inria.fr (8.13.6/8.13.6) with ESMTP id l95FCFjT031805 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=OK) for ; Fri, 5 Oct 2007 17:12:15 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAAB/xBUdC+VLklmdsb2JhbACCPTSLSAIBAQcEBhERBw X-IronPort-AV: E=Sophos;i="4.21,236,1188770400"; d="scan'208";a="17341616" Received: from wx-out-0506.google.com ([66.249.82.228]) by mail4-smtp-sop.national.inria.fr with ESMTP; 05 Oct 2007 17:12:14 +0200 Received: by wx-out-0506.google.com with SMTP id h28so553516wxd for ; Fri, 05 Oct 2007 08:12:13 -0700 (PDT) Received: by 10.142.171.6 with SMTP id t6mr1580918wfe.1191597132476; Fri, 05 Oct 2007 08:12:12 -0700 (PDT) Received: by 10.142.80.4 with HTTP; Fri, 5 Oct 2007 08:12:12 -0700 (PDT) Message-ID: <28fa90930710050812i204e975ap847e7474ec9580bc@mail.gmail.com> Date: Fri, 5 Oct 2007 08:12:12 -0700 From: "Luca de Alfaro" To: "David Teller" Subject: Re: [Caml-list] Re: Why can't I call a function over a subclass? Cc: "Zheng Li" , caml-list@inria.fr In-Reply-To: <28fa90930710050759m682d8b65g72a31cc311acc276@mail.gmail.com> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_28326_31401983.1191597132467" References: <28fa90930710050048p3d6f4e8cs8e13d0fe49d296f2@mail.gmail.com> <4705EF58.3040605@bik-gmbh.de> <1191580233.6509.26.camel@Blefuscu> <87ejg9oms3.fsf@pps.jussieu.fr> <1191592931.6509.33.camel@Blefuscu> <28fa90930710050759m682d8b65g72a31cc311acc276@mail.gmail.com> X-Miltered: at concorde with ID 4706544F.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; ens-lyon:01 cheers:01 0200,:01 ens-lyon:01 subtypes:01 val:01 bool:01 beginner's:01 ocaml:01 bug:01 cheers:01 0200,:01 subtypes:01 val:01 bool:01 ------=_Part_28326_31401983.1191597132467 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline 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 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 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 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 = > > > > > > > _______________________________________________ > > 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 > > > > ------=_Part_28326_31401983.1191597132467 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline 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


------=_Part_28326_31401983.1191597132467--