caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Christian Lindig <lindig@eecs.harvard.edu>
To: Caml Mailing List <caml-list@inria.fr>
Subject: Re: [Caml-list] code duplication when abstracting using explicit signatures
Date: Sun, 23 Mar 2003 10:58:41 +0100	[thread overview]
Message-ID: <20030323095841.GA709@eecs.harvard.edu> (raw)
In-Reply-To: <Pine.LNX.4.44.0303221614460.7493-100000@grace.speakeasy.net>

[-- Attachment #1: Type: text/plain, Size: 1458 bytes --]

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/

[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]

      reply	other threads:[~2003-03-23 20:01 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-03-20 23:32 Jeffrey J. Cook
2003-03-22 12:07 ` Michal Moskal
2003-03-23  0:52   ` brogoff
2003-03-23  9:58     ` Christian Lindig [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20030323095841.GA709@eecs.harvard.edu \
    --to=lindig@eecs.harvard.edu \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).