caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Martin Jambon <martin_jambon@emailuser.net>
To: Andreas Rossberg <AndreasRossberg@web.de>
Cc: caml-list@yquem.inria.fr
Subject: AST traversal functions (was: SML->OCaml)
Date: Tue, 8 Mar 2005 12:46:02 -0800 (PST)	[thread overview]
Message-ID: <Pine.LNX.4.44.0503081209240.1306-100000@localhost> (raw)
In-Reply-To: <005701c523be$d1997260$14b2a8c0@wiko>

On Tue, 8 Mar 2005, Andreas Rossberg wrote:

> In fact, it would be much more complicated. First, identifier status is
> scoped. Constructors are frequently defined locally. In particular, this may
> happen implicitly through the use of "open". To derive the required
> information you hence needed to perform a complete binding analysis,
> including modules and signatures.
>
> Then, SML actually allows constructor status to be withdrawn from an
> identifier. For example, the following program is valid:
>
>   signature S = sig type t val x : t end
>   structure A : S = struct datatype t = x end
>
> There are few programs that make use of this possibility, but I expect them
> to coincide with those that violate the usual case conventions in the first
> place. An SML-to-OCaml translator had to go to quite some length to
> translate such programs.
>
> In summary, to deal with constructor status correctly (not to mention stuff
> like datatype replication, local, records, user-defined fixity, etc.) you
> basically need half an SML frontend. It seems out of scope for a Camlp4 hack
> to be more than a simple approximation.

Yes, but I believe there should be a convenient way at least to reuse the
syntax tree produced by the current converter, and convert the incorrect
uppercase/lowercase identifiers.
It just requires a good root-to-leaves substitution function which does
not ask us to match explicitely every kind of node of a given type (which
is extremely repetitive and error-prone, even with quotations). I already
thought of doing this (actually automatically deriving such a higher-order
function from the type definition of the AST: Pcaml.expr and friends).

Example:

let X = 1 in fun x -> X

We should be able to specify that
  let $patt$ = $e1$ in $e2$

adds the binding to the current environment for converting expr.
And by default, everything is just "traversed".
For instance, the case $e1$ + $e2$ which is itself an expression should
not be explicitely unconstructed/substituted/reconstructed, that would be
done automatically.
This would let us focus only on the specific cases such as "open",
"let ... in", "fun ...", "let ..." (or "val ..."), simple identifiers and
module-related issues.


Martin


  reply	other threads:[~2005-03-08 20:46 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-03-07  2:14 [Caml-list] SML->OCaml Harrison, John R
2005-03-07 21:39 ` Martin Jambon
2005-03-08  9:11   ` Andreas Rossberg
2005-03-08 20:46     ` Martin Jambon [this message]
2005-03-08 21:00       ` [Caml-list] AST traversal functions (was: SML->OCaml) Hal Daume III

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=Pine.LNX.4.44.0503081209240.1306-100000@localhost \
    --to=martin_jambon@emailuser.net \
    --cc=AndreasRossberg@web.de \
    --cc=caml-list@yquem.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).