From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by walapai.inria.fr (8.13.6/8.13.6) with ESMTP id p0OAmDWb005478 for ; Mon, 24 Jan 2011 11:48:13 +0100 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AokFADfnPE2CiAFm/2dsb2JhbACWR44dc7sChVAE X-IronPort-AV: E=Sophos;i="4.60,369,1291590000"; d="scan'208";a="87788262" Received: from leb.cs.unibo.it ([130.136.1.102]) by mail2-smtp-roc.national.inria.fr with ESMTP/TLS/ADH-AES256-SHA; 24 Jan 2011 11:48:07 +0100 Received: from ssl.cs.unibo.it (ssl.cs.unibo.it [127.0.0.1]) (Authenticated sender: hidden) by leb.cs.unibo.it (Postfix) with ESMTPSA id 0E35E355B7 for ; Mon, 24 Jan 2011 11:48:03 +0100 (CET) Message-ID: <4D3D58DF.2090607@cs.unibo.it> Date: Mon, 24 Jan 2011 11:47:59 +0100 From: Matthias Puech User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.13) Gecko/20101208 Thunderbird/3.1.7 MIME-Version: 1.0 To: caml-list@inria.fr Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: [Caml-list] Avoiding ml/mli duplication cheaply 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 type t = A val x : t include types of mli let x = A type t module M : sig type u end val x : M.u include types of mli with type t = int type M.u = string let x = "hello"