From: Martin Jambon <martin.jambon@ens-lyon.org>
To: David Teller <David.Teller@univ-orleans.fr>
Cc: OCaml <caml-list@inria.fr>
Subject: Re: [Caml-list] Hiding a public module/type?
Date: Tue, 04 Nov 2008 00:38:31 +0100 [thread overview]
Message-ID: <490F8B77.608@ens-lyon.org> (raw)
In-Reply-To: <1225748157.6328.105.camel@Blefuscu>
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/
next prev parent reply other threads:[~2008-11-03 23:38 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-11-03 21:35 David Teller
2008-11-03 23:38 ` Martin Jambon [this message]
2008-11-10 14:04 ` [Caml-list] " David Teller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=490F8B77.608@ens-lyon.org \
--to=martin.jambon@ens-lyon.org \
--cc=David.Teller@univ-orleans.fr \
--cc=caml-list@inria.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox