Version française
Home     About     Download     Resources     Contact us    
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: -- (:)
From: Khoo Yit Phang <khooyp@c...>
Subject: Problem with class method and polymorphic variants
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