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 pA2JfKoA025538 for ; Wed, 2 Nov 2011 20:41:25 +0100 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgUCAH+csU7RVaE2kGdsb2JhbABDmjeHRQGHbAgiAQEBAQkJDQcUBCGCCwIsARseAxIJB10BEQEFAVedFIJbCotUgmCFVj2IcAIFCokGBIgHjA2NOT2EDg X-IronPort-AV: E=Sophos;i="4.69,445,1315173600"; d="scan'208";a="116358820" Received: from mail-fx0-f54.google.com ([209.85.161.54]) by mail4-smtp-sop.national.inria.fr with ESMTP/TLS/RC4-SHA; 02 Nov 2011 20:41:25 +0100 Received: by faar19 with SMTP id r19so1542070faa.27 for ; Wed, 02 Nov 2011 12:41:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:content-type; bh=X0WkPq/QF+plp9o+Ax56Ac6GsiuJph8XGO84hxIAYV8=; b=QsHByE60JqY2Bvzkxsu/4jCOz/gCfizQYN/fpyDgpUWI10CW4gAbitxFe+qTk72M8s Zf/IEXAoOAir3O3RDDpZrQGand3YxfiPvNFWq7WO8xrH95GfAU7EYqBeM/L7QmdCTp5x wDAa76PU8hn5fF3FfSR4AjqPTZYBRS6naU8iw= MIME-Version: 1.0 Received: by 10.223.94.143 with SMTP id z15mr6383533fam.32.1320262884018; Wed, 02 Nov 2011 12:41:24 -0700 (PDT) Received: by 10.152.6.227 with HTTP; Wed, 2 Nov 2011 12:41:23 -0700 (PDT) Date: Wed, 2 Nov 2011 13:41:23 -0600 Message-ID: From: Anthony Tavener To: caml-list@inria.fr Content-Type: multipart/alternative; boundary=001517478f1a364a5d04b0c5a891 Subject: [Caml-list] Nested module exposing type from parent? --001517478f1a364a5d04b0c5a891 Content-Type: text/plain; charset=ISO-8859-1 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 To date, I've defined the type in the Type submodule, which is then used by the parent module. The unsatisfactory quality of this is that Vec.Type.t is the "true" type. Ideally the concrete type would live at Vec.t, with "open Vec.Type" bringing the fields of the type into scope. As background, here are examples of opening different features of the Vec module: let c = Vec.add a b open Vec.Prefixed let c = vadd a b open Vec.Ops let c = a +| b open Vec.Type let c = Vec.add a {x;y;z=0.} Apologies if this is really beginner-list material. It's minor, but has been bugging me. Thank-you for looking, Tony --001517478f1a364a5d04b0c5a891 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
I've been struggling with this occasionally...

I'm using nested modules to "open" access to select fea= tures of a module. My problem is I can't find a way to *expose* types i= n the parent module through such nested modules.

A simplified example of what I'm looking at:
<= div>
=A0 module Vec =3D struct

=A0 = =A0 type t =3D { x: int; y: int }
=A0 =A0 let make x y =3D {x;y}<= /div>
=A0 =A0 let add a b =3D {x=3Da.x+b.x; y=3Da.y+b.y}

=A0 =A0 module Type =3D
=A0 =A0 =A0 (* someth= ing which has type t =3D Vec.t,
=A0 =A0 =A0 =A0* with exposed str= ucture when "open"ed.
=A0 =A0 =A0 =A0* Also note that V= ec is not really an
=A0 =A0 =A0 =A0* explicit module like this; instead it
=A0 =A0 = =A0 =A0* is implemented in vec.ml *)
=A0 end

Example usage...

=A0 let n =3D Vec.make 2 5
=A0 open Vec.Type
=A0 let m =3D {x=3D1;y=3D2}
=A0 = Vec.add m n


To date, I've defin= ed the type in the Type submodule, which is then used by the parent module.= The unsatisfactory quality of this is that Vec.Type.t is the "true&qu= ot; type. Ideally the concrete type would live at Vec.t, with "open Ve= c.Type" bringing the fields of the type into scope.

As background, here are examples of opening different f= eatures of the Vec module:

=A0 let c =3D Vec.add a= b

=A0 open Vec.Prefixed
=A0 let c =3D v= add a b

=A0 open Vec.Ops
=A0 let c =3D a +| b

=A0 open Vec.Type
=A0 let c =3D Vec.add a {x;y;= z=3D0.}

Apologies if this is really beginner-list = material. It's minor, but has been bugging me.
Thank-you for looking,

=A0Tony

=
--001517478f1a364a5d04b0c5a891--