Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Alain Frisch <alain@frisch.fr>
To: David Allsopp <dra-news@metastack.com>,
	 Romain Bardou <romain.bardou@inria.fr>,
	"caml-list@inria.fr" <caml-list@inria.fr>
Subject: Re: [Caml-list] automatic extaction of the .mli (and a little more) from the .ml
Date: Tue, 04 Jun 2013 10:22:00 +0200	[thread overview]
Message-ID: <51ADA3A8.7070008@frisch.fr> (raw)
In-Reply-To: <E51C5B015DBD1348A1D85763337FB6D9CC7F39B8@Remus.metastack.local>

On 06/04/2013 09:53 AM, David Allsopp wrote:
> I have wondered if this problem is perhaps looked at the wrong way
> around - in other words, the complaint takes the form "how can we
> export to the .mli file automatically" rather than "how can we
> *import* from the .ml file automatically". The thing I do find
> irritating maintaining .mli/.ml files is having to type anything out
> twice - and for the most part that means fully exported type
> declarations. Say you have a simple module:

I'd rather do it the other way around: maintain the type declaration in 
the .mli and import it in the .ml file.

And, guess what, there is also a POC of such a tool in the 
extension_points branch.  It allows you to write in the .ml file:

   type t = [%copy_typedef]

to copy the concrete definition from the .mli file.  This also works for 
module types, and you can also import a definition from another .ml or 
.mli file:

   module type S = [%copy_typedef]
   type loc = [%copy_typedef "../../parsing/location.mli" t]


The [%id ...] syntax is the other new syntactic feature introduced by 
the extension_points branch (in addition to attributes).  Contrary to 
attributes which annotate already well-formed code and which can thus be 
ignored by the type-checker, [%...] extensions can used in place of an 
expression, type, pattern, etc, and they need to be expanded by a -ppx 
rewriter.



The tool:

http://caml.inria.fr/cgi-bin/viewvc.cgi/ocaml/branches/extension_points/experimental/frisch/copy_typedef.ml?revision=HEAD&view=markup

And an example:

http://caml.inria.fr/cgi-bin/viewvc.cgi/ocaml/branches/extension_points/experimental/frisch/test_copy_typedef.mli?revision=HEAD&view=markup

http://caml.inria.fr/cgi-bin/viewvc.cgi/ocaml/branches/extension_points/experimental/frisch/test_copy_typedef.ml?revision=HEAD&view=markup



-- Alain

  reply	other threads:[~2013-06-04  8:22 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-05-31  3:43 Francois Berenger
2013-05-31  5:31 ` Malcolm Matalka
2013-05-31  6:26   ` Francois Berenger
2013-05-31  9:10     ` Romain Bardou
2013-06-03  1:33       ` Francois Berenger
2013-06-04  7:53       ` David Allsopp
2013-06-04  8:22         ` Alain Frisch [this message]
2013-06-04  8:54           ` David Allsopp
2013-06-04  8:22         ` Romain Bardou
2013-06-04  9:05           ` David Allsopp
2013-05-31 23:13     ` oliver
2013-06-03  1:28       ` Francois Berenger
2013-06-03 12:01         ` Malcolm Matalka
2013-05-31 15:21   ` [Caml-list] " Hongbo Zhang
2013-05-31 15:42     ` Yaron Minsky
2013-05-31 23:20       ` Jacques Le Normand
2013-06-01  9:12     ` Florent Monnier
2013-06-03 17:12 ` [Caml-list] " Alain Frisch
2013-06-04  0:30   ` Francois Berenger
2013-06-04  8:36     ` Alain Frisch

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=51ADA3A8.7070008@frisch.fr \
    --to=alain@frisch.fr \
    --cc=caml-list@inria.fr \
    --cc=dra-news@metastack.com \
    --cc=romain.bardou@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