[
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: | 2008-11-03 (23:38) |
From: | Martin Jambon <martin.jambon@e...> |
Subject: | Re: [Caml-list] Hiding a public module/type? |
David Teller wrote: > Dear list, > > In order to simplify the error messages for users of my library, I'd > like to hide some type aliasing. > > I have the following: > > (*** module [Inner], defined in inner.mli ***) > type t > > > (*** module [Outer], defined in outer.mli ***) > type t = Inner.t > val f : t -> t > > > Now, module [Inner] is only useful to define the library and shouldn't > be visible from the outside. Unfortunately, for the moment, whenever a > client makes a type error involving [f], the error message looks like > > # f 5;; > ^ > This expression has type int but is used with type > Outer.t = Inner.t > > Is there a simple way of turning this error message into > > This expression has type int but is used with type > Outer.t > ? One solution consists in using submodules for achieving an intermediate level of privacy ("friend" modules): $ cat inner.mli type t = int $ cat outer.mli type t = Inner.t val f : t -> t $ cat packed.mli module Outer : sig type t val f : t -> t end Create valid inner.ml and outer.ml files but no packed.ml. Compile: $ ocamlc -c inner.mli $ ocamlc -c outer.mli $ ocamlc -c inner.ml $ ocamlc -c outer.ml Pack: $ ocamlc -c packed.mli $ ocamlc -pack -o packed.cmo inner.cmo outer.cmo Then you only have to install the packed.cm* files. It gives you: # Packed.Outer.f 5;; This expression has type int but is here used with type Packed.Outer.t Martin -- http://mjambon.com/