English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

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: 2002-05-25 (03:55)
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

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