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 mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by yquem.inria.fr (Postfix) with ESMTP id 63377BCAF for ; Wed, 4 Mar 2009 15:03:21 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Ak0BACAZrklCbwQbkGdsb2JhbACVAQEBAQEHCwwHEQTCMoJ0gRQG X-IronPort-AV: E=Sophos;i="4.38,301,1233529200"; d="scan'208";a="22035863" Received: from out3.smtp.messagingengine.com ([66.111.4.27]) by mail2-smtp-roc.national.inria.fr with ESMTP; 04 Mar 2009 15:03:20 +0100 Received: from compute1.internal (compute1.internal [10.202.2.41]) by out1.messagingengine.com (Postfix) with ESMTP id C8C132D9B52; Wed, 4 Mar 2009 09:03:19 -0500 (EST) Received: from heartbeat1.messagingengine.com ([10.202.2.160]) by compute1.internal (MEProxy); Wed, 04 Mar 2009 09:03:19 -0500 X-Sasl-enc: 2y3QD7+zlDtnUspl6mXEZvQnlmeLfFjmd+ttmaqbbxFy 1236175399 Received: from [192.168.1.10] (ALyon-157-1-28-106.w86-193.abo.wanadoo.fr [86.193.119.106]) by mail.messagingengine.com (Postfix) with ESMTPSA id 0AD6520A32; Wed, 4 Mar 2009 09:03:18 -0500 (EST) Message-ID: <49AE898A.7040607@ens-lyon.org> Date: Wed, 04 Mar 2009 15:00:42 +0100 From: Martin Jambon User-Agent: Thunderbird 2.0.0.17 (X11/20081008) MIME-Version: 1.0 To: Vsevolod Fedorov Cc: caml-list@yquem.inria.fr Subject: Re: [Caml-list] recursive records with weak hashtbl References: <49AE8296.5040009@mail.ru> In-Reply-To: <49AE8296.5040009@mail.ru> Content-Type: text/plain; charset=KOI8-R Content-Transfer-Encoding: 7bit X-Spam: no; 0.00; ens-lyon:01 recursive:01 hashtbl:01 hash:01 mutable:01 mutable:01 hash:01 functor:01 parametrized:01 recursive:01 struct:01 hashtbl:01 sig:01 struct:01 wrote:01 Vsevolod Fedorov wrote: > Hello! > > I want to define two records referencing each other. First record (A) > has direct reference to second (B) and second (B) has weak hash table to > list records A, which have reference to it. For example (pseudo code): > > type a > { > id : int ; > mutable field1 : string; > mutable b : B; > } > type b > { > id : int; > mutable field2 : string; > a_list : Weak-Hashtbl(a); (* they referenced me *) > } > > Is it possible at all? > Is it possible with A and B declarations in separate files? > > Any hints and references are welcomed. Assuming your weak hash table module is created by a functor parametrized by type "a", the problem is solved with recursive modules. They are documented as a language extension in the reference manual: http://caml.inria.fr/pub/docs/manual-ocaml/manual021.html#toc75 Here is some code that compiles and runs without raising the Undefined_recursive_module exception: module rec W : Weak.S = Weak.Make ( struct type t = X.a let equal = ( = ) let hash = Hashtbl.hash end ) and X : sig type a = { id : int ; mutable field1 : string; mutable b : b; } and b = { id : int; mutable field2 : string; a_list : W.t; (* they referenced me *) } end = struct type a = { id : int ; mutable field1 : string; mutable b : b; } and b = { id : int; mutable field2 : string; a_list : W.t; (* they referenced me *) } end Martin -- http://mjambon.com/