Version française
Home     About     Download     Resources     Contact us    
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, 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.

    <<types>>=
    type foo = (* large, shared concrete type *)

    <<foo.mli>>=
    <<types>>
    (* other abstract types, function signatures *)

    <<foo.ml>>=
    <<types>>
    (* 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/