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=none autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by yquem.inria.fr (Postfix) with ESMTP id 292EBBBC1 for ; Mon, 24 Mar 2008 10:02:37 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AhcCAGAL50dQW+UCiGdsb2JhbACRFwEBAQ8mlFuBCA X-IronPort-AV: E=Sophos;i="4.25,545,1199660400"; d="scan'208";a="9879419" Received: from concorde.inria.fr ([192.93.2.39]) by mail1-smtp-roc.national.inria.fr with ESMTP; 24 Mar 2008 10:02:37 +0100 Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by concorde.inria.fr (8.13.6/8.13.6) with ESMTP id m2O92Wi1025783 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=OK) for ; Mon, 24 Mar 2008 10:02:36 +0100 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AhcCAGAL50dQW+UCiGdsb2JhbACRFwEBAQ8mlFuBCA X-IronPort-AV: E=Sophos;i="4.25,545,1199660400"; d="scan'208";a="9879415" Received: from main.gmane.org (HELO ciao.gmane.org) ([80.91.229.2]) by mail1-smtp-roc.national.inria.fr with ESMTP; 24 Mar 2008 10:02:32 +0100 Received: from list by ciao.gmane.org with local (Exim 4.43) id 1JdiZa-0005RP-9a for caml-list@inria.fr; Mon, 24 Mar 2008 09:02:30 +0000 Received: from 178.56.101-84.rev.gaoland.net ([84.101.56.178]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 24 Mar 2008 09:02:30 +0000 Received: from vanicat by 178.56.101-84.rev.gaoland.net with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 24 Mar 2008 09:02:30 +0000 X-Injected-Via-Gmane: http://gmane.org/ To: caml-list@inria.fr From: Remi Vanicat Subject: Re: recursive types Date: Mon, 24 Mar 2008 10:02:20 +0100 Organization: none Message-ID: <87hcewpk9v.dlv@maison.homelinux.org> References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: 178.56.101-84.rev.gaoland.net Mail-Copy-To: never User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.1 (gnu/linux) Cancel-Lock: sha1:w1sBp0sa5DKxl5ulD2l7uy2wpjc= Sender: news X-Miltered: at concorde with ID 47E76E28.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; recursive:01 recursive:01 polymorphism:01 node:01 node:01 beginner's:01 ocaml:01 polymorphic:01 beginners:01 monomorphic:01 remi:01 writes:01 vanicat:01 vanicat:01 groups:02 "Jacques Le Normand" writes: > hello again list > is it possible to have mutually recursive classes and types? I'm trying to > implement the zipper, and this is what I came up with: Not directly, but you can use polymorphism to have it: class type ['a] node_wrapper = object method identify : string method get_child_location : 'a end class virtual ['a] nodeable = object(self) method virtual to_node_wrapper : 'a node_wrapper end type path = (location nodeable list * location * location nodeable list) option and location = Loc of location nodeable * path you could even do something like : class type ['a] pre_node_wrapper = object method identify : string method get_child_location : 'a end class virtual ['a] pre_nodeable = object(self) method virtual to_node_wrapper : 'a pre_node_wrapper end type path = (location pre_nodeable list * location * location pre_nodeable list) option and location = Loc of location pre_nodeable * path class type node_wrapper = [location] pre_node_wrapper class virtual nodeable = [location] pre_nodeable (you could also make the type polymorphic, and the class monomorphic if you declare the type before the class and class type). You probably should come on the Beginner's list, where such question could be answered (see http://groups.yahoo.com/group/ocaml_beginners) -- RĂ©mi Vanicat