caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Nested module exposing type from parent?
@ 2011-11-02 19:41 Anthony Tavener
  2011-11-02 20:19 ` Vincent Aravantinos
  2011-11-03  0:41 ` Martin Jambon
  0 siblings, 2 replies; 8+ messages in thread
From: Anthony Tavener @ 2011-11-02 19:41 UTC (permalink / raw)
  To: caml-list

[-- Attachment #1: Type: text/plain, Size: 1359 bytes --]

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

[-- Attachment #2: Type: text/html, Size: 2016 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2011-11-03  1:04 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-11-02 19:41 [Caml-list] Nested module exposing type from parent? Anthony Tavener
2011-11-02 20:19 ` Vincent Aravantinos
     [not found]   ` <CAN=ouMTApZjpU-CaZtdL4njXtmtRu++7fzJBJL3w3FRcHfjtSA@mail.gmail.com>
     [not found]     ` <CAN=ouMS9rqqNR3KgCBnnjC_HcMrUnftVw643mkmhC_vrpXfv1A@mail.gmail.com>
2011-11-02 21:14       ` Fwd: " Anthony Tavener
2011-11-02 23:01         ` Gabriel Scherer
2011-11-03  0:06           ` Vincent Aravantinos
2011-11-03  1:03           ` Anthony Tavener
2011-11-03  0:41 ` Martin Jambon
2011-11-03  1:04   ` Anthony Tavener

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).