Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] Polymorphic method problem
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Olivier Andrieu <andrieu@i...>
Subject: Re: [Caml-list] Polymorphic method problem
 Christian Szegedy [Tue, 06 Jul 2004]:
 > Can anyone tell me, why does the following piece of
 > code fail to compile, and how can I achieve
 > equivalent effect in the most convenient way?
 >
 > class a () =
 >    object(self)
 >       method f : 'a. ((< f : unit; .. > as 'a) -> unit) = fun other -> 
 > other#f 
 >       method g = (self :> a)
 >    end

Defining a class type beforehand helps:

,----
| # class type a_t = object method f : < f : unit; ..> -> unit method g : a_t end ;;
| class type a_t =
|   object method f : < f : unit; .. > -> unit method g : a_t end
| 
| # class a () : a_t = object (self) 
|     method f : 'a. ((< f : unit; .. > as 'a) -> unit) = fun other ->
|   other#f 
|     method g = (self :> a_t) 
|   end ;;
| class a : unit -> a_t
`----

-- 
   Olivier

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