* Hiding a public module/type?
@ 2008-11-03 21:35 David Teller
2008-11-03 23:38 ` [Caml-list] " Martin Jambon
0 siblings, 1 reply; 3+ messages in thread
From: David Teller @ 2008-11-03 21:35 UTC (permalink / raw)
To: OCaml
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
?
Thanks,
David
--
David Teller-Rajchenbach
Security of Distributed Systems
http://www.univ-orleans.fr/lifo/Members/David.Teller
Angry researcher: French Universities need reforms, but the LRU act
brings liquidations.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Caml-list] Hiding a public module/type?
2008-11-03 21:35 Hiding a public module/type? David Teller
@ 2008-11-03 23:38 ` Martin Jambon
2008-11-10 14:04 ` David Teller
0 siblings, 1 reply; 3+ messages in thread
From: Martin Jambon @ 2008-11-03 23:38 UTC (permalink / raw)
To: David Teller; +Cc: OCaml
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/
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2008-11-10 14:12 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-11-03 21:35 Hiding a public module/type? David Teller
2008-11-03 23:38 ` [Caml-list] " Martin Jambon
2008-11-10 14:04 ` David Teller
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox