From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=AWL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by yquem.inria.fr (Postfix) with ESMTP id BCF87BBAF for ; Sat, 12 Jul 2008 16:12:02 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: ApoEAOJXeEjAXQIm/2dsb2JhbACocg X-IronPort-AV: E=Sophos;i="4.30,349,1212357600"; d="scan'208";a="15054216" Received: from discorde.inria.fr ([192.93.2.38]) by mail3-smtp-sop.national.inria.fr with ESMTP; 12 Jul 2008 16:12:02 +0200 Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id m6CEC1pX025373 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=OK) for ; Sat, 12 Jul 2008 16:12:01 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: ApoEAOJXeEhQRFuw/2dsb2JhbACocg X-IronPort-AV: E=Sophos;i="4.30,349,1212357600"; d="scan'208";a="15035655" Received: from furbychan.cocan.org ([80.68.91.176]) by mail1-smtp-roc.national.inria.fr with ESMTP/TLS/AES256-SHA; 12 Jul 2008 16:12:01 +0200 Received: from rich by furbychan.cocan.org with local (Exim 4.63) (envelope-from ) id 1KHfpQ-0002TJ-NS for caml-list@inria.fr; Sat, 12 Jul 2008 15:12:00 +0100 Date: Sat, 12 Jul 2008 15:12:00 +0100 To: caml-list@inria.fr Subject: Why can't immediate objects be extended? Message-ID: <20080712141200.GA8634@annexia.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.13 (2006-08-11) From: Richard Jones X-Miltered: at discorde with ID 4878BBB1.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; syntax:01 node:01 node:01 ocaml:01 val:01 rec:01 rec:01 inherit:01 inherit:01 precisely:01 caml:02 tree:02 tree:02 string:02 string:02 I'm wondering if there's a reason why one cannot inherit from immediate objects? (See description at: http://caml.inria.fr/pub/docs/manual-ocaml/manual005.html#ss:immediate-objects) Is it just a syntax problem because the 'inherit' keyword currently needs to take a class type, or is there a deeper reason? This is the code I'd like to write (non-working, obviously): type 'a tree = Leaf of string | Node of 'a tree * 'a * 'a tree let none = object end let tree = Node (Leaf "1", none, Leaf "2") let rec string_of_tree = function | Leaf str -> str | Node (left, _, right) -> "(" ^ string_of_tree left ^ "," ^ string_of_tree right ^ ")" let rec annotate = function | (Leaf _ as t) -> t | (Node (left, parent_obj, right) as t) -> let obj = object inherit (typeof parent_obj) method str = string_of_tree t end in Node (annotate left, obj, annotate right) let tree = annotate tree The problematic function is 'annotate'. I believe I want annotate to have a type along these lines (again, this is not precisely OCaml code because I've used alpha to stand for '..'): val annotate : < 'a > tree -> < str : string; 'a > tree Rich. -- Richard Jones Red Hat