caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Malcolm Matalka <mmatalka@gmail.com>
To: Gabriel Scherer <gabriel.scherer@gmail.com>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Expressing module sig and impl in mli file
Date: Wed, 19 Sep 2012 00:40:23 +0200	[thread overview]
Message-ID: <CAKziXDWDAuhUNa_muTL9T9vjuO9_LrLR-wknCciPMCSHhkA6pw@mail.gmail.com> (raw)
In-Reply-To: <CAKziXDV=tG+y2XJ4zS54waZKuRS8BSsH7bQ+pOyDROG7CGcypw@mail.gmail.com>

I spoke too soon!  Below is my testcase and error.  Where did I go wrong?

foo.mli:
open Core.Std

module Bar : sig
  include Identifier with type t = String.t
end

foo.ml:
open Core.Std

module Bar : Identifier = String

The error:
       Type declarations do not match:
         type t = Bar.t
       is not included in
         type t = Core.Std.String.t

/M

On Tue, Sep 18, 2012 at 11:31 PM, Malcolm Matalka <mmatalka@gmail.com> wrote:
> Thanks for the response.  I think I found another way to express what I'm after:
>
> module Foo : sig include Bar with type t = Baz.t end
>
> For the specific use case I have (trying to create a module that is an
> Identifier from Core) this seems to work nicely.
>
> /M
>
> On Tue, Sep 18, 2012 at 11:13 PM, Gabriel Scherer
> <gabriel.scherer@gmail.com> wrote:
>> From the outside, there is no point in trying to make a difference
>> between an "interface" and "concrete types": what users see of the
>> module is exactly its interface, just as what you see of a value
>> (through an interface boundary) is its type only. There are exotic
>> cases where you could want to publish a value definition (or module
>> implementation) through a component boundary, but that's probably not
>> your concern here.
>>
>> So my intuitive answer (but maybe some other posters will differ) is
>> that, in an interface, only "module Foo : Bar" makes sense. I do not
>> understand why you would want the implementation to also be available.
>> You may be facing a problem that is different than the one you think.
>> Could you provide a concrete example of what you're trying to do?
>>
>> Making a guess: a mistake people often make when using the OCaml
>> module system is to seal a module with abstract types when they
>> actually don't want to hide the types, but only to check that the
>> signature are compatible. For example, with the signature "module type
>> Ty = sig type t end", people will try to write "module M : Ty = struct
>> type t = int end" and then be surprised than "(1 : M.t)" does not
>> type-check. This is because "module M : Ty = <Foo>" is equivalent to
>> "module M = (<Foo> : Ty)" which coerces <Foo> into the signature Ty
>> (where "t" is abstract), and no richer. A workaround is to define
>> "module M = <Foo>" and then separately "module M_unused = (M : Ty)" if
>> you want to make sure that the interface is compatible, or to refine
>> it with "module M : (Ty with type t = int) = <Foo>". Not sure that is
>> actually your problem, though.
>>
>> Finally, if you have a module implementation and are not sure what its
>> precise, most permissive signature is, "ocamlc -i" can help you by
>> printing the inferred interface.
>>
>> On Tue, Sep 18, 2012 at 11:02 PM, Malcolm Matalka <mmatalka@gmail.com> wrote:
>>> I'm sure this question has been asked before but I didn't see it in
>>> the Ocaml FAQ and I'm not sure how to express it for a search.
>>>
>>> In short, how do I express the following line in a .mli file:
>>>
>>> module Foo : Bar = Baz
>>>
>>> What I want to accomplish is make present the module Foo to the user,
>>> where they know both the interface and the concerete types on Foo.
>>>
>>> Thanks!
>>>
>>> /Malcolm
>>>
>>> --
>>> Caml-list mailing list.  Subscription management and archives:
>>> https://sympa-roc.inria.fr/wws/info/caml-list
>>> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
>>> Bug reports: http://caml.inria.fr/bin/caml-bugs
>>>

  reply	other threads:[~2012-09-18 22:40 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-09-18 21:02 Malcolm Matalka
2012-09-18 21:13 ` Gabriel Scherer
2012-09-18 21:31   ` Malcolm Matalka
2012-09-18 22:40     ` Malcolm Matalka [this message]
2012-09-19  2:11       ` Edgar Friendly
2012-09-19  7:11         ` David House
2012-09-19  7:36           ` Malcolm Matalka
2012-09-19  7:49             ` David House
2012-09-19  7:51               ` David House
2012-09-19  8:00                 ` Malcolm Matalka
2012-09-19  8:11                   ` Gabriel Scherer
2012-09-19  7:25       ` Jacques Garrigue

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=CAKziXDWDAuhUNa_muTL9T9vjuO9_LrLR-wknCciPMCSHhkA6pw@mail.gmail.com \
    --to=mmatalka@gmail.com \
    --cc=caml-list@inria.fr \
    --cc=gabriel.scherer@gmail.com \
    /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;
as well as URLs for NNTP newsgroup(s).