Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Matthias Puech <puech@cs.unibo.it>
To: caml-list@inria.fr
Subject: [Caml-list] Avoiding ml/mli duplication cheaply
Date: Mon, 24 Jan 2011 11:47:59 +0100	[thread overview]
Message-ID: <4D3D58DF.2090607@cs.unibo.it> (raw)

Dear Camlists,

Motivated by a recent discussion on the list, I wrote a small camlp5 
syntax extension that allows to avoid the duplication of type 
definitions between ml and mli. I thought it might be helpful to someone 
one day. It adds two very simple constructions to the module system:
* [mli] is a module type. If the current file has a .mli, [mli] is 
expanded to the .mli's content.
* [types of S] is a module expression if S is a module type. It is 
expanded to the structure containing all type declarations and module 
types of S recursively (skipping [val]s etc.).
Restriction: S has to be a [sig ... end] or a [S with ...] construct 
(because it is done within camlp5)

These two allow to include the contents of a mli into a ml and perform 
instantiations of abstract types (see examples below). You can find the 
extension (70 lines of code) together with tests at:

git clone http://helm.cs.unibo.it/~puech/repos/typdef.git

Hope it helps! Cheers,
     -m

<simple.mli>
type t = A
val x : t

<simple.ml>
include types of mli
let x = A

<test.mli>
type t
module M : sig
   type u
end
val x : M.u

<test.ml>
include types of mli with
   type t = int
   type M.u = string
let x = "hello"


                 reply	other threads:[~2011-01-24 10:48 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=4D3D58DF.2090607@cs.unibo.it \
    --to=puech@cs.unibo.it \
    --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