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 mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by yquem.inria.fr (Postfix) with ESMTP id 6D912BBC1 for ; Mon, 24 Mar 2008 09:40:56 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: ArMPAIMF50dT9QHmWGdsb2JhbACBW48yARYEEBeUZA X-IronPort-AV: E=Sophos;i="4.25,545,1199660400"; d="scan'208";a="8736186" Received: from pop.bulldoghome.com (HELO bdmail1.accesst.com) ([83.245.1.230]) by mail2-smtp-roc.national.inria.fr with ESMTP; 24 Mar 2008 09:40:56 +0100 Received: from host-84-9-233-154.dslgb.com ([84.9.233.154] helo=[192.168.123.191]) by bdmail1.accesst.com with esmtpa (Exim 4.50) id 1JdiCP-0001vt-BN; Mon, 24 Mar 2008 08:38:33 +0000 Message-ID: <47E7684D.5050201@ed.ac.uk> Date: Mon, 24 Mar 2008 08:37:33 +0000 From: Jeremy Yallop User-Agent: Mozilla-Thunderbird 2.0.0.9 (X11/20080110) MIME-Version: 1.0 To: Jacques Le Normand Cc: caml-list caml-list Subject: Re: [Caml-list] recursive types References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Spam: no; 0.00; recursive:01 recursive:01 syntax:01 node:01 node:01 sig:01 struct:01 sig:01 elided:01 struct:01 wrote:01 rec:01 rec:01 caml-list:01 define:02 Jacques Le Normand wrote: > is it possible to have mutually recursive classes and types? Yes, using recursive modules. The syntax is a little heavy, though, since you have to write some of the definitions in both the signature and the implementation. > class type node_wrapper = > object > method identify : string > method get_child_location : location > end > > class virtual nodeable = > object(self) > method virtual to_node_wrapper : node_wrapper > end > > type path = (nodeable list * location * nodeable list) option > and location = Loc of nodeable * path This might be written as module rec M : sig class type node_wrapper = object method identify : string method get_child_location : M.location end class virtual nodeable : object method virtual to_node_wrapper : node_wrapper end type path = (nodeable list * M.location * nodeable list) option type location = Loc of nodeable * path end = struct class type node_wrapper = object method identify : string method get_child_location : M.location end class virtual nodeable = object method virtual to_node_wrapper : node_wrapper end type path = (nodeable list * M.location * nodeable list) option type location = Loc of nodeable * path end The definitions which merely define type aliases (node_wrapper and path) can be shortened in the implementation section if you prefer: module rec M : sig [elided] end = struct class type node_wrapper = M.node_wrapper class virtual nodeable = object method virtual to_node_wrapper : node_wrapper end type path = M.path type location = Loc of nodeable * path end Jeremy.