Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] About polymorphic methods and recursive classes
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Jacques Garrigue <garrigue@k...>
Subject: Re: [Caml-list] About polymorphic methods and recursive classes
From: Sebastien Briais <sebastien.briais@epfl.ch>
> >># class virtual ['a] visitor =
> >>   object
> >>     method virtual caseNil : 'a
> >>   end
> >>   and virtual int_list =
> >>   object
> >>     method virtual visit : 'a.('a visitor -> 'a)
> >>   end
> >>   ;;
> >>class virtual ['a] visitor : object method virtual caseNil : 'a end
> >>class virtual int_list : object method virtual visit : 'a visitor ->
> >>'a end
> 
> I am still puzzled by the answer of the interpreter which says me that
> "v has type 'a visitor; It has no method caseNil"
> although it has inferred just before that
> "class virtual ['a] visitor : object method virtual caseNil : 'a end"
> 
> Moreover, it seems odd to me that it works with class types but not without.
> These class types should be inferred by Ocaml, shouldn't they ? (and 
> they seems
> to be correctly inferred in my example (in the first part of it))

Actually no. Polymorphic methods are not inferred, but declared.
And polymorphic type variables should not be used as parameters to
simultaneously defined types.
Actually, your mutually recursive definition should not be accepted to
begin with. It clearly results in a wrong internal type.

The problem is not virtual class vs. class types. The virtual class
version will work if you drop the recursion (replace "and" by "class").

> So I ask again : how should I interpret the error message given by ocaml ?

As a bug in the compiler. The error should be reported earlier.

   Jacques Garrigue

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners