caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Problem with class method and polymorphic variants
@ 2008-06-24 18:17 Khoo Yit Phang
  2008-06-25  3:12 ` [Caml-list] " Jacques Garrigue
  0 siblings, 1 reply; 4+ messages in thread
From: Khoo Yit Phang @ 2008-06-24 18:17 UTC (permalink / raw)
  To: caml-list; +Cc: Khoo Yit Phang

Hi,

I discovered that the attached snippet of Ocaml does not compile in  
ocamlc, but does work in the ocaml toplevel (tested in v3.10.0 and  
3.10.2). Removing anything (except the :int annotation) causes the  
error to go away. Is it a bug in the type-checker?

# cat polymorphic-variants-methods-bug.ml
class ['a] c (a : 'a) =
    object (s)
        method s = s
        method d : int = match a with `A b -> b#num
    end

# ocamlc polymorphic-variants-methods-bug.ml
The implementation polymorphic-variants-methods-bug.ml
does not match the interface (inferred signature):
Type declarations do not match:
  type 'a c = < d : int; s : 'a c >
    constraint 'a = [< `A of < num : int; .. > & < num : int; .. > ]
is not included in
  type 'a c = < d : int; s : 'a c >
    constraint 'a =
      [< `A of < num : int; .. > & < num : int; .. > & < num : int; ..  
 > ]

#ocamlc -i  polymorphic-variants-methods-bug.ml
class ['a] c :
  'a ->
  object ('b)
    constraint 'a = [< `A of < num : int; .. > ]
    method d : int
    method s : 'b
  end

Yit
June 24, 2008


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Caml-list] Problem with class method and polymorphic variants
  2008-06-24 18:17 Problem with class method and polymorphic variants Khoo Yit Phang
@ 2008-06-25  3:12 ` Jacques Garrigue
  2008-06-25  5:17   ` Khoo Yit Phang
  0 siblings, 1 reply; 4+ messages in thread
From: Jacques Garrigue @ 2008-06-25  3:12 UTC (permalink / raw)
  To: khooyp; +Cc: caml-list

From: Khoo Yit Phang <khooyp@cs.umd.edu>
> Hi,
> 
> I discovered that the attached snippet of Ocaml does not compile in  
> ocamlc, but does work in the ocaml toplevel (tested in v3.10.0 and  
> 3.10.2). Removing anything (except the :int annotation) causes the  
> error to go away. Is it a bug in the type-checker?
> 
> # cat polymorphic-variants-methods-bug.ml
> class ['a] c (a : 'a) =
>     object (s)
>         method s = s
>         method d : int = match a with `A b -> b#num
>     end

Of course this is a bug. I added it myself to the bug tracker.
By the way you could also trigger it in the toplevel by giving
explicitly a module signature (this is what ocamlc does internally).

This is now fixed in CVS, branch release310.
Note that you may still have other kinds of problems using
upper-bounded polymorpic variants inside constraints. Just report them
as you go...

Cheers,

Jacques Garrigue


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Caml-list] Problem with class method and polymorphic variants
  2008-06-25  3:12 ` [Caml-list] " Jacques Garrigue
@ 2008-06-25  5:17   ` Khoo Yit Phang
  2008-06-26  2:46     ` Jacques Garrigue
  0 siblings, 1 reply; 4+ messages in thread
From: Khoo Yit Phang @ 2008-06-25  5:17 UTC (permalink / raw)
  To: Jacques Garrigue; +Cc: Khoo Yit Phang, caml-list

Hi,

Thanks for the quick response! I've encountered another strange one  
that may be related. The code below compiles only if you remove the  
underscore in the method "_a". The error message is similar to the  
earlier one, but I think it's a different problem?

class ['a] node d =
     object
         method _d : 'a = d
         method p (x : 'a) = "<data>"
     end

class ['a] pnode data =
     object (self)
         inherit ['a] node data
         (* doesn't compile with the underscore in "_a" *)
         method _a = self
         method p = function `P p -> p#name
     end

Yit
June 25, 2008

On Jun 24, 2008, at 11:12 PM, Jacques Garrigue wrote:

> From: Khoo Yit Phang <khooyp@cs.umd.edu>
>> Hi,
>>
>> I discovered that the attached snippet of Ocaml does not compile in
>> ocamlc, but does work in the ocaml toplevel (tested in v3.10.0 and
>> 3.10.2). Removing anything (except the :int annotation) causes the
>> error to go away. Is it a bug in the type-checker?
>>
>> # cat polymorphic-variants-methods-bug.ml
>> class ['a] c (a : 'a) =
>>    object (s)
>>        method s = s
>>        method d : int = match a with `A b -> b#num
>>    end
>
> Of course this is a bug. I added it myself to the bug tracker.
> By the way you could also trigger it in the toplevel by giving
> explicitly a module signature (this is what ocamlc does internally).
>
> This is now fixed in CVS, branch release310.
> Note that you may still have other kinds of problems using
> upper-bounded polymorpic variants inside constraints. Just report them
> as you go...
>
> Cheers,
>
> Jacques Garrigue


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Caml-list] Problem with class method and polymorphic variants
  2008-06-25  5:17   ` Khoo Yit Phang
@ 2008-06-26  2:46     ` Jacques Garrigue
  0 siblings, 0 replies; 4+ messages in thread
From: Jacques Garrigue @ 2008-06-26  2:46 UTC (permalink / raw)
  To: khooyp; +Cc: caml-list

From: Khoo Yit Phang <khooyp@cs.umd.edu>

> Thanks for the quick response! I've encountered another strange one  
> that may be related. The code below compiles only if you remove the  
> underscore in the method "_a". The error message is similar to the  
> earlier one, but I think it's a different problem?
> 
> class ['a] node d =
>      object
>          method _d : 'a = d
>          method p (x : 'a) = "<data>"
>      end
> 
> class ['a] pnode data =
>      object (self)
>          inherit ['a] node data
>          (* doesn't compile with the underscore in "_a" *)
>          method _a = self
>          method p = function `P p -> p#name
>      end

The problem seems the same as the previous one, and it goes away with
the latest release310 version of typecore.ml.
As to why the name of the method matters, it may be related to the
order in which the checking is done. Since types are graphs, this ends
up being relevant (but only when there is a bug!)

Jacques Garrigue


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2008-06-26  2:47 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-06-24 18:17 Problem with class method and polymorphic variants Khoo Yit Phang
2008-06-25  3:12 ` [Caml-list] " Jacques Garrigue
2008-06-25  5:17   ` Khoo Yit Phang
2008-06-26  2:46     ` Jacques Garrigue

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