Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] What about polymorphic methods?
[ 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] What about polymorphic methods?
From: Alessandro Baretta <alex@baretta.com>

>      method left_iter : ('a -> 'b) -> 'b list
>      method right_iter : ('a -> 'c) -> 'c list
> 
> Is there any way, then, to define polymorphic versions of 
> the two iterators?

Indeed, iterators are one of the major reasons to have polymorphic
methods in ocaml (the other one being implicit subtyping of
arguments). They are already in CVS, and will be present in ocaml
3.05.

With the CVS version, you would have to write

   method left_iter : 'b. ('a -> 'b) -> 'b list = fun f -> ...
   method right_iter : 'b. ('a -> 'b) -> 'b list = fun f -> ...

Of course, 'b is no longer a parameter of the class.
Note that polymorphic methods can only be called on objects whose type
is (at least partially) known, so you may have to add a few extra type
annotations to your code.

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