English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
[Caml-list] code duplication when abstracting using explicit signatures
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2003-03-23 (20:01)
From: Christian Lindig <lindig@e...>
Subject: Re: [Caml-list] code duplication when abstracting using explicit signatures
On Sat, Mar 22, 2003 at 04:52:13PM -0800, brogoff@speakeasy.net wrote:
> On Sat, 22 Mar 2003, Michal Moskal wrote:
> > Use example_types.mli and example.ml/mli. AFAIR you can only put types
> > in example_types, not even exceptions.
> And making that example_types.ml instead of .mli will allow exceptions (and 
> values!), but I'd prefer having a pure .mli file as you suggest, and just 
> creating a fourth file example_exns.ml for any example exceptions. 

Just for completeness, here is another trick: when you are using a
literate programming tool like NoWEB you can let it do the code
duplication: the file foo.nw contains both interface and implementation
as named chunks, plus some documentation. A named chunk <<types>> that
contains code shared between interface and implementation can be
referenced from both. When foo.mli and foo.ml are extracted from foo.nw
for compilation, all references are resolved and the shared code shows
up in both.

    type foo = (* large, shared concrete type *)

    (* other abstract types, function signatures *)

    (* rest of implementation *)

In comparison, this approach goes the opposite way: instead of having
more source files, have just one *.nw file that allows internal
references for code chunks.

-- Christian

Christian Lindig         http://www.eecs.harvard.edu/~lindig/