Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] About polymorphic methods and recursive classes
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Damien <Damien.Pous@e...>
Subject: Re: [Caml-list] About polymorphic methods and recursive classes
On Sat, 22 Mar 2003 12:22:44 +0100
Sébastien Briais <sebastien.briais@epfl.ch> wrote:

> Hello,
hello

> # class virtual ['a] visitor =
>    object
>      method virtual caseNil : 'a
>    end
>    and virtual int_list =
>    object
>      method virtual visit : 'a.('a visitor -> 'a)
>    end
>    ;;
> class virtual ['a] visitor : object method virtual caseNil : 'a end
> class virtual int_list : object method virtual visit : 'a visitor ->
> 'a end
> 
> # class nil =
>    object
>      inherit int_list
>      method visit v = v#caseNil
>    end
>    ;;
> This expression has type 'a visitor
> It has no method caseNil

it seems to work with class types :

#   class type ['a] visitor_t = object 
	method caseNil: 'a 
end;;
  class type ['a] visitor_t = object method caseNil : 'a end

# class type int_list_t = object 
	method visit: 'a. ('a visitor_t) -> 'a
end;; 
  class type int_list_t = object method visit : 'a visitor_t -> 'a end

# class nil: int_list_t = object
  method visit: 'a. ('a visitor_t) -> 'a = fun v -> v#caseNil
end;;
      class nil : int_list_t


damien

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