caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Avoiding ml/mli duplication cheaply
@ 2011-01-24 10:47 Matthias Puech
  0 siblings, 0 replies; only message in thread
From: Matthias Puech @ 2011-01-24 10:47 UTC (permalink / raw)
  To: caml-list

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"


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2011-01-24 10:48 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-01-24 10:47 [Caml-list] Avoiding ml/mli duplication cheaply Matthias Puech

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).