Aha! That's more like what I was going for, Martin.
On 11/02/2011 12:41 PM, Anthony Tavener wrote:> * is implemented in vec.ml <http://vec.ml> *)
> 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
> endI hope I understand the problem correctly.
>
> Example usage...
>
> let n = Vec.make 2 5
> open Vec.Type
> let m = {x=1;y=2}
> Vec.add m n
In order for that code to work, you can do this:
module Type = struct
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}
type t' = t = { x: int; y: int }
type t = t' = { x: int; y: int }
(* something which has type t = Vec.t,* is implemented in vec.ml <http://vec.ml> *)
* with exposed structure when "open"ed.
* Also note that Vec is not really an
* explicit module like this; instead it
end
end
Or more simply:
module Vec = struct
module Type = struct
type t = { x: int; y: int }
(* something which has type t = Vec.t,* is implemented in vec.ml <http://vec.ml> *)
* with exposed structure when "open"ed.
* Also note that Vec is not really an
* explicit module like this; instead it
end
type t = Type.t = { x: int; y: int }
let make x y = {x;y}end
let add a b = {x=a.x+b.x; y=a.y+b.y}
Now you can open either Vec or Vec.Type and have direct access to the
record fields.
Martin
--
Caml-list mailing list. Subscription management and archives:
https://sympa-roc.inria.fr/wws/info/caml-list
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs