From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: * X-Spam-Status: No, score=1.0 required=5.0 tests=AWL,DNS_FROM_SECURITYSAGE autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by yquem.inria.fr (Postfix) with ESMTP id A204DBBAF for ; Tue, 4 Nov 2008 00:38:36 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AioDAJ8aD0nAXQImgWdsb2JhbACUFAEBFiK3WoNS X-IronPort-AV: E=Sophos;i="4.33,539,1220220000"; d="scan'208";a="16821116" Received: from discorde.inria.fr ([192.93.2.38]) by mail2-smtp-roc.national.inria.fr with ESMTP; 04 Nov 2008 00:38:36 +0100 Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id mA3NcZkh000325 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=OK) for ; Tue, 4 Nov 2008 00:38:36 +0100 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Ak8BAOsZD0lCbwQdc2dsb2JhbACUFAEMCgsHEQS3ZoNS X-IronPort-AV: E=Sophos;i="4.33,539,1220220000"; d="scan'208";a="18819567" Received: from out5.smtp.messagingengine.com ([66.111.4.29]) by mail3-smtp-sop.national.inria.fr with ESMTP; 04 Nov 2008 00:38:35 +0100 Received: from compute1.internal (compute1.internal [10.202.2.41]) by out1.messagingengine.com (Postfix) with ESMTP id 425F6191745; Mon, 3 Nov 2008 18:38:34 -0500 (EST) Received: from heartbeat1.messagingengine.com ([10.202.2.160]) by compute1.internal (MEProxy); Mon, 03 Nov 2008 18:38:34 -0500 X-Sasl-enc: Xb/8qLSaeUtpr/CxTD/YDZmQnbHt0H39l33P0SE99GCn 1225755513 Received: from [192.168.1.61] (dsl092-191-028.sfo1.dsl.speakeasy.net [66.92.191.28]) by mail.messagingengine.com (Postfix) with ESMTPSA id 712C1247E6; Mon, 3 Nov 2008 18:38:33 -0500 (EST) Message-ID: <490F8B77.608@ens-lyon.org> Date: Tue, 04 Nov 2008 00:38:31 +0100 From: Martin Jambon User-Agent: Thunderbird 2.0.0.17 (X11/20081008) MIME-Version: 1.0 To: David Teller Cc: OCaml Subject: Re: [Caml-list] Hiding a public module/type? References: <1225748157.6328.105.camel@Blefuscu> In-Reply-To: <1225748157.6328.105.camel@Blefuscu> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Miltered: at discorde with ID 490F8B7B.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; ens-lyon:01 mli:01 mli:01 val:01 submodules:01 val:01 sig:01 ocamlc:01 ocamlc:01 -pack:01 cmo:01 cmo:01 wrote:01 compile:01 caml-list:01 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/