English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    
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: Lauri Alanko <la@iki.fi>
> On Sat, May 25, 2002 at 12:55:30PM +0900, Jacques Garrigue wrote:
> > 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 -> ...
>                          ^^^
> 
> Is this type parameter declaration really necessary? Since class type
> parameters are explicitly declared already, can't method-specific type
> parameters be recognized automatically?

When writing a class type, you can omit them:

class ['a] collection : object
  method left_iter : ('a -> 'b) -> 'b list
  method right_iter : ('a -> 'b) -> 'b list
end

This is ok because these method types are exact.
However, in an implementation type annotations denote only constraints.
That is, this 'b could actually be instanciated to something inside
the class, or related to another type parameter by a constraint. The
only way to say that it is going to be polymorphic at this level is to
write it explicitly. Try:

class c = object (self)
  method m1 : 'a -> 'a = fun x -> x
  method m2 = self#m1 1
end

---------------------------------------------------------------------------
Jacques Garrigue      Kyoto University     garrigue at kurims.kyoto-u.ac.jp
		<A HREF=http://wwwfun.kurims.kyoto-u.ac.jp/~garrigue/>JG</A>
-------------------
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