Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

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: -- (:)
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, wrote:
> On Sat, 22 Mar 2003, Michal Moskal wrote:
> > Use example_types.mli and AFAIR you can only put types
> > in example_types, not even exceptions.
> And making that 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 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 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