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

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Karl Zilles <zilles@1...>
Subject: Re: [Caml-list] polymorphic methods in objects?
Nicolas Cannasse wrote:
> two ways of doing that :
> 
> first, having a parameterized object :
> 
> class ['a] my_object : object
>     method dummy_init : 'a -> unit
> end
> 
> But perhaps here you really want that any value passed to your object is ok.
> So you have to use a polymorphic method, which is not bound to the class
> type :
> 
> class my_object : object
>     method dummy_init : 'a . 'a -> unit
> end
> 
> This way, you cannot of course store the parameter into a field of my_object
> this it is not polymorphic.

The stuff Nicolas mentions is covered in sections 3.9 and 3.10 of the 
current manual.  You should probably read these sections, because use of 
polymorphic methods can sometimes require type constraints.

http://caml.inria.fr/ocaml/htmlman/manual005.html#ss:parameterized-classes
http://caml.inria.fr/ocaml/htmlman/manual005.html#ss:polymorphic-methods



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