Version française
Home     About     Download     Resources     Contact us    
Browse thread
Why can't immediate objects be extended?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Richard Jones <rich@a...>
Subject: Re: [Caml-list] Why can't immediate objects be extended?
On Sat, Jul 12, 2008 at 03:12:00PM +0100, Richard Jones wrote:
>         let obj = object
>   	  inherit (typeof parent_obj)
>   	  method str = string_of_tree t
>         end in
>         Node (annotate left, obj, annotate right)

Further exploration reveals I can write this, which is _almost_ what I
want:

  let obj = object
    inherit object method parent = parent_obj end
    method str = string_of_tree t
   end in ...

except the indirection through a parent method is not helpful for what
I'm trying to achieve (an extensible static type that doesn't depend
on the order in which the type is extended).

The types produced by this are:

  val annotate : 'a tree -> < parent : 'a; str : string > tree = <fun>

  val tree : < parent : <  >; str : string > tree = (* ... *)

Rich.

-- 
Richard Jones
Red Hat