Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] functional objects
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Didier Remy <Didier.Remy@i...>
Subject: Re: [Caml-list] functional objects
> Anyway, one of the things I find lacking is a way to call a subclass 
> constructor in the copy constructor.  In other words, I'd like to have 
> some way to do the following:
> 
> 	(* class type with only public methods exposed *)
> 	class type foo = object method f: unit end
> 
> 	(* class with private members *)
> 	class foo x : foo = object
> 	  val x: int = x
> 	  method f = ()
> 	end
> 
> 	(* derived functional subclass (notice method g) *)
> 	class bar y = object
> 	  inherit foo 0
> 	  val y: int = y
> 	  method g a b = {< foo a; y = b >}
> 	end
> 
> What I want is for a superclass class to be able to expose an interface 
> to subclasses for constructing copies with arguments.  Is this a bad 
> idea?  Has it already been considered and rejected?  Just curious.

Would the following code makes you happy?

        (* class type with only public methods exposed,
           plus a private overriding method foo *)
        class type foo_ = 
          object ('a) method f : unit method private foo : int -> 'a end;;

        (* class with private members *)
        class foo x : foo_ = object
          val x: int = x
          private method foo a = {< x = a >}
          method f = ()
        end;;

        (* derived functional subclass (notice method g) *)
        class bar y = object
          inherit foo 0
          val y: int = y
          method g a b = {< y = b >} # foo a 
        end;;

Didier Rémy
-------------------
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