From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by walapai.inria.fr (8.13.6/8.13.6) with ESMTP id pA2KJmAc026766 for ; Wed, 2 Nov 2011 21:19:48 +0100 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AloBAE+lsU7RVdg2kGdsb2JhbABDqWoIIgEBAQEJCQ0HFAQhgXIBAQEEEgIsARscAQEDDAYFCw0JFg8JAwIBAgEREQEFARwGDQEHAQEen1gKi1SCYIVUPYhwAgUKiQYElBSGXoZbPYQL X-IronPort-AV: E=Sophos;i="4.69,445,1315173600"; d="scan'208,217";a="127815863" Received: from mail-qw0-f54.google.com ([209.85.216.54]) by mail1-smtp-roc.national.inria.fr with ESMTP/TLS/RC4-SHA; 02 Nov 2011 21:19:43 +0100 Received: by qadz32 with SMTP id z32so835559qad.27 for ; Wed, 02 Nov 2011 13:19:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:content-type; bh=eyZcqdmsSpp2wC+hO8LrfZpmuWfOzQXaFhSbUFLn90A=; b=S+YlRxucmnF4W4IciiHIIFqaNvaNWH9So/DqUMpTCXCwwllJgBdKcmBMhzTdqqWhEh Rb5q1qeAbEDK9W7jndH1hlum93IvrRyNHC7j09IAYk34lPmfshd9RPStsER/aNgZV13D WsEmxYqGKu91E7WKNlvz7qSC+PaamoQabRUGU= Received: by 10.229.72.164 with SMTP id m36mr759508qcj.39.1320265182230; Wed, 02 Nov 2011 13:19:42 -0700 (PDT) Received: from page.encs.concordia.ca (page.encs.concordia.ca. [132.205.221.212]) by mx.google.com with ESMTPS id df3sm3614348qab.6.2011.11.02.13.19.40 (version=SSLv3 cipher=OTHER); Wed, 02 Nov 2011 13:19:40 -0700 (PDT) Message-ID: <4EB1A5DB.8070405@gmail.com> Date: Wed, 02 Nov 2011 16:19:39 -0400 From: Vincent Aravantinos User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.23) Gecko/20110928 Red Hat/3.1.15-1.el6_1 Thunderbird/3.1.15 MIME-Version: 1.0 To: Anthony Tavener CC: caml-list@inria.fr References: In-Reply-To: Content-Type: multipart/alternative; boundary="------------010904060505090808030907" Subject: Re: [Caml-list] Nested module exposing type from parent? This is a multi-part message in MIME format. --------------010904060505090808030907 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Using "include" instead of "open" would work, ie. turning your example into: module Vec_main = 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} end module Vec = struct include Vec_main module Type = struct include Vec_main ... end end Then: # let n = Vec.make 2 5;; val n : Vec.t = {Vec.x = 2; Vec.y = 5} # open Vec.Type;; # let m = {x=1;y=2};; val m : Vec.Type.t = {x = 1; y = 2} # Vec.add m n;; - : Vec.t = {Vec.x = 3; Vec.y = 7} Cheers -- Vincent Aravantinos - Postdoctoral Fellow, Concordia University, Hardware Verification Group On 11/02/2011 03: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 > > > 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 > --------------010904060505090808030907 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Using "include" instead of "open" would work, ie. turning your example into:

module Vec_main = 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}
end

module Vec = struct
  include Vec_main
  module Type = struct
    include Vec_main
    ...
  end
end

Then:
# let n = Vec.make 2 5;;
val n : Vec.t = {Vec.x = 2; Vec.y = 5}
# open Vec.Type;;
# let m = {x=1;y=2};;
val m : Vec.Type.t = {x = 1; y = 2}
# Vec.add m n;;
- : Vec.t = {Vec.x = 3; Vec.y = 7}

Cheers

-- 
Vincent Aravantinos - Postdoctoral Fellow, Concordia University, Hardware Verification Group

On 11/02/2011 03: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


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


--------------010904060505090808030907--