caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: "Andreas Rossberg" <AndreasRossberg@web.de>
To: <caml-list@yquem.inria.fr>
Subject: Re: [Caml-list] SML->OCaml
Date: Tue, 8 Mar 2005 10:11:16 +0100	[thread overview]
Message-ID: <005701c523be$d1997260$14b2a8c0@wiko> (raw)
In-Reply-To: <Pine.LNX.4.44.0503071308440.2011-100000@localhost>

Martin Jambon <martin_jambon@emailuser.net> wrote:
>
> > Does this version do anything about SML programs that violate OCaml's
> > "uppercase identifier" convention? I recently tried something similar,
> > and while it did a competent job of parsing most of the syntax of SML,
> > it just reported errors for SML value bindings starting with an
> > uppercase letter. It would be nice if it just mapped such names to
> > "lowercase_XXX" or something so that the result could at least be
> > compiled. Or is that too "context sensitive" to be easy?
>
> [I don't know SML and I am not an expert in Camlp4. And I haven't tried
> the SML-to-OCaml converter]
>
> The converter needs a way to tell whether a given identifier is a type
> constructor (such as None or Some) or not. Thus the converter needs to
> remember the accessible type definitions (either from the standard
> library of SML or from other modules). That is possible, by creating some
> auxilliary files that contain this information (maybe .cmi files could be
> parsed but anyway the type definitions have to be analysed during the
> preprocessing of a file). It doesn't seem to be implemented
> in pa_sml.ml but a few hundred lines of additional code could do it (or
> maybe less).

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.

Cheers,

  - Andreas


  reply	other threads:[~2005-03-08  9:07 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-03-07  2:14 Harrison, John R
2005-03-07 21:39 ` Martin Jambon
2005-03-08  9:11   ` Andreas Rossberg [this message]
2005-03-08 20:46     ` AST traversal functions (was: SML->OCaml) Martin Jambon
2005-03-08 21:00       ` [Caml-list] " Hal Daume III
  -- strict thread matches above, loose matches on Subject: below --
2005-03-08 18:17 [Caml-list] SML->OCaml Harrison, John R
2005-03-08 22:54 ` Andreas Rossberg
2005-03-11  8:31   ` Norman Scaife
2005-03-06 20:03 SML->OCaml Konstantine Arkoudas
2005-03-06 22:15 ` [Caml-list] SML->OCaml Martin Jambon

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='005701c523be$d1997260$14b2a8c0@wiko' \
    --to=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).