Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] a class as method parameter...
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Michael <micha-1@f...>
Subject: [Caml-list] a class as method parameter...
Hi,

I don't understand why this doesn't work:

class one = object
  val name = "test"
  method name = name
end;;
class two = object
  method take_one o -> o#name
end;;

that gives:
Some type variables are unbound in this type:
  class two : object method take_one : < name : 'a; .. > -> 'a end
The method take_one has type (< name : 'b; .. > as 'a) -> 'b where 'a
is unbound

I have to declare:
class two = object
  method take_one : 'a. (#one as 'a) -> string = fun o ->  o#name
end;;

.. to get it work (from chapter 3.10 )

why has it to be declared this way? 
( and not:
class two = object
  method take_one ( o : #one ) =  o#name
end;;

which also does not work:
The method take_one has type (#one as 'a) -> string where 'a is unbound ) ??

thanks,
 Michael
 



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