From: Lauri Alanko <la@iki.fi>
To: caml-list@inria.fr
Subject: Re: [Caml-list] Avoiding ml/mli code duplication
Date: Tue, 28 Dec 2010 18:54:00 +0200 [thread overview]
Message-ID: <20101228165359.GC12021@melkinpaasi.cs.helsinki.fi> (raw)
In-Reply-To: <4D19FB54.3000607@frisch.fr>
On Tue, Dec 28, 2010 at 03:59:32PM +0100, Alain Frisch wrote:
> (** BarDefs.ml **)
> module type S = sig
> type t
> type u = A of t
> end
>
>
> (** Bar.mli **)
> include BarDefs.S
> val x: u list
>
>
> (** Bar.ml **)
> type t = X
> module rec S_impl : BarDefs.S with type t := t = S_impl
> include S_impl
> let x = [A X]
That's neat. You are using the recursive module trick that allows one
to convert a value-less signature into a module:
<http://ocaml.janestreet.com/?q=node/84>. Effectively, you replace my
example's functor application with signature refining.
(Incidentally, your code can simplified somewhat by moving the
signature S into the body of BarDefs.mli and then using "module type
of BarDefs" instead of "BarDefs.S".)
However, the recursive module trick seems like quite a kludge. Perhaps
there should be a "legitimized" way of producing a module with a
certain value-less signature. For instance, instead of "module rec M :
S = M" just allow "module M : S" within a module definition if S has
no values?
There's another approach to my original problem that unfortunately
doesn't seem to work. In principle, we could have:
(*** BarCore.mli ***)
type t
(*** BarCore.ml ***)
type t = X
(*** BarDefs.ml ***)
include BarCore
type u = A of t
(*** Bar.mli ***)
include module type of BarDefs
val x : u list
(*** Bar.ml ***)
include BarDefs
let x = [A X]
Except, of course, that the constructor X is not visible in Bar.ml. I
can't immediately see a way to make it visible in Bar.ml without also
making it visible in Bar.mli. BarCore would need to have a separate
"package-internal" signature that Bar.ml could use. Is there any way
to achive this?
Lauri
prev parent reply other threads:[~2010-12-28 16:54 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-12-28 14:02 Lauri Alanko
2010-12-28 14:16 ` Richard W.M. Jones
2010-12-28 14:59 ` Alain Frisch
2010-12-28 16:54 ` Lauri Alanko [this message]
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=20101228165359.GC12021@melkinpaasi.cs.helsinki.fi \
--to=la@iki.fi \
--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