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 (01:41)
From: Alessandro Baretta <alex@b...>
Subject: [Caml-list] What about polymorphic methods?
I am writing a very simple class to handle bidirectional 
(bidi) lists in an object-functional manner. I have come up 
with a curious problem. The following text is the toplevel's 
output when it is passed my code.

type 'a bidi = Elem of 'a bidi * 'a * 'a bidi | Null
class ['a, 'b, 'c] bidi_list :
   'a list ->
     method head : 'a bidi
     method left_iter : ('a -> 'b) -> 'b list
     method right_iter : ('a -> 'c) -> 'c list
     method tail : 'a bidi
     val first : 'a bidi
     val last : 'a bidi
#   new bidi_list [1;2;3;4;5];;
- : (int, '_a, '_b) bidi_list = <obj>

The basic idea is that I want to convert a value with type 
'a list to a value belonging to class ['a] bidi_list. Now, 
if I leave 'b and 'c out of the parameter list my code 
refuses to compile, but even when I add 'b and 'c as type 
parameters, the type checker specializes them to '_b and 
'_c, which are not polymorphic.

Is there any way, then, to define polymorphic versions of 
the two iterators?

Alex Baretta

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