Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
Problem with class method and polymorphic variants
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2008-06-25 (05:18)
From: Khoo Yit Phang <khooyp@c...>
Subject: Re: [Caml-list] Problem with class method and polymorphic variants

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 =
         method _d : 'a = d
         method p (x : 'a) = "<data>"

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

June 25, 2008

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

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