From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by walapai.inria.fr (8.13.6/8.13.6) with ESMTP id pA30aFKY002352 for ; Thu, 3 Nov 2011 01:36:15 +0100 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AsQBAJLhsU5CbwQdkWdsb2JhbABEmj6POiIBAQEBCQsLBxQEIYFyAQEFQDgCDwsYCRYPCQMCAQIBRRMIAQGqJJMaB4kQiAuRPoxU X-IronPort-AV: E=Sophos;i="4.69,446,1315173600"; d="scan'208";a="116427379" Received: from out5.smtp.messagingengine.com ([66.111.4.29]) by mail4-smtp-sop.national.inria.fr with ESMTP/TLS/ADH-AES256-SHA; 03 Nov 2011 01:36:09 +0100 Received: from compute3.internal (compute3.nyi.mail.srv.osa [10.202.2.43]) by gateway1.nyi.mail.srv.osa (Postfix) with ESMTP id 2050220311 for ; Wed, 2 Nov 2011 20:36:08 -0400 (EDT) Received: from frontend1.nyi.mail.srv.osa ([10.202.2.160]) by compute3.internal (MEProxy); Wed, 02 Nov 2011 20:36:08 -0400 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=message-id:date:from:mime-version:to :subject:references:in-reply-to:content-type :content-transfer-encoding; s=smtpout; bh=KzYJtEzWRNi4ogmwpXSn19 X9tR8=; b=LNOO3QzP1P9MynQjgLFLGZfIhh6MeybRl9JshcobmsvAXpxgL792sl vdORIj7+5RAr6cZjhNFiICyx/Le8jhOJH9irf45QoAsWtzJxBpHyamZ5cq8AKccp j2y2fb+ZWlSYNuC7MUO3DSR9N8AgOsU0pOPBPkoqGvtJnLVbyllj4= X-Sasl-enc: ae9BzrTb5Jp18GeQLMVGVZGv4pK9vv8swIoP6vklmNbw 1320280567 Received: from [192.168.1.206] (64-71-1-165.static.wiline.com [64.71.1.165]) by mail.messagingengine.com (Postfix) with ESMTPSA id C3B9E8E0F88 for ; Wed, 2 Nov 2011 20:36:07 -0400 (EDT) Message-ID: <4EB1E325.4020207@ens-lyon.org> Date: Wed, 02 Nov 2011 17:41:09 -0700 From: Martin Jambon User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.9) Gecko/20101023 Lightning/1.0b3pre Thunderbird/3.1.3 MIME-Version: 1.0 To: caml-list@inria.fr References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Subject: Re: [Caml-list] Nested module exposing type from parent? On 11/02/2011 12:41 PM, Anthony Tavener wrote: > I've been struggling with this occasionally... > > I'm using nested modules to "open" access to select features of a > module. My problem is I can't find a way to *expose* types in the parent > module through such nested modules. > > A simplified example of what I'm looking at: > > module Vec = struct > > type t = { x: int; y: int } > let make x y = {x;y} > let add a b = {x=a.x+b.x; y=a.y+b.y} > > module Type = > (* something which has type t = Vec.t, > * with exposed structure when "open"ed. > * Also note that Vec is not really an > * explicit module like this; instead it > * is implemented in vec.ml *) > end > > Example usage... > > let n = Vec.make 2 5 > open Vec.Type > let m = {x=1;y=2} > Vec.add m n I hope I understand the problem correctly. In order for that code to work, you can do this: module Vec = struct type t = { x: int; y: int } let make x y = {x;y} let add a b = {x=a.x+b.x; y=a.y+b.y} module Type = struct type t' = t = { x: int; y: int } type t = t' = { x: int; y: int } (* something which has type t = Vec.t, * with exposed structure when "open"ed. * Also note that Vec is not really an * explicit module like this; instead it * is implemented in vec.ml *) end end Or more simply: module Vec = struct module Type = struct type t = { x: int; y: int } (* something which has type t = Vec.t, * with exposed structure when "open"ed. * Also note that Vec is not really an * explicit module like this; instead it * is implemented in vec.ml *) end type t = Type.t = { x: int; y: int } let make x y = {x;y} let add a b = {x=a.x+b.x; y=a.y+b.y} end Now you can open either Vec or Vec.Type and have direct access to the record fields. Martin