From: Alain Frisch <alain@frisch.fr>
To: Lauri Alanko <la@iki.fi>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Avoiding ml/mli code duplication
Date: Tue, 28 Dec 2010 15:59:32 +0100 [thread overview]
Message-ID: <4D19FB54.3000607@frisch.fr> (raw)
In-Reply-To: <20101228140247.GB12021@melkinpaasi.cs.helsinki.fi>
On 12/28/2010 3:02 PM, Lauri Alanko wrote:
> In this situation, I'm not quite sure what's the best way to
> proceed.
Here is another possibility:
===================================================================
(** 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]
===================================================================
I can also mention a local extension we use at LexiFi: a compilation
unit (.ml) for which an explicit signature (.mli) exists is type-checked
as a recursive module with itself. (Currently, we disallow recursive
references to value-like components.) So in the example above, the
definition of the module type S could be put in Bar.mli:
===================================================================
(** Bar.mli **)
module type S = sig
type t
type u = A of t
end
include S
val x: u list
(** Bar.ml **)
module type S = Bar.S
type t = X
module rec S_impl : S with type t := t = S_impl
include S_impl
let x = [A X]
===================================================================
The same extension allows for easy recursion between, say, type and
class type definitions:
===================================================================
(** Bar.mli **)
type t = A of Bar.u
class type u = object
method foo: t
end
.....
(** Bar.ml **)
type t = A of Bar.u
class type u = Bar.u
......
===================================================================
What could be useful would be an extra extension to have an "include"
statement for specific type declarations, so that the Bar.ml above could
be written directly:
type t = include Bar.t (* same as type t = Bar.t = A of Bar.u *)
class type u = Bar.u
.....
-- Alain
next prev parent reply other threads:[~2010-12-28 14:59 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 [this message]
2010-12-28 16:54 ` Lauri Alanko
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=4D19FB54.3000607@frisch.fr \
--to=alain@frisch.fr \
--cc=caml-list@inria.fr \
--cc=la@iki.fi \
/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).