Browse thread
"opening" record types
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Jeremy Yallop <jeremy.yallop@e...> |
| Subject: | Re: [Caml-list] "opening" record types |
Philippe Wang wrote:
> Instead of :
> # module M = struct type t = { a : int ; b : int } end ;;
> module M : sig type t = { a : int; b : int; } end
>
> Write :
> # module M = struct type t = { a : int ; b : int } module N = struct
> type t = M.t = { a : int ; b : int } end end ;;
I don't think this code is quite what you intended.
# ({a = 0 ; b = 0 } : M.t );;
Characters 1-17:
({a = 0 ; b = 0 } : M.t );;
^^^^^^^^^^^^^^^^
This expression has type t = M.t but is here used with type M.t
I like the idea, though. You can avoid duplicating the type definition
by writing the inner module first.
module M =
struct
module N = struct type t = { a : int; b : int } end
include N
end
Then, as before:
open M.N
{ a = 0; b = 0 }
> That way, when you change or add definitions, it's easy to spread
> changes, and you export only what you want to export...
Yes. Unforunately, the technique is only useful if you have control of
the module that you want to import.
Jeremy.