Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
RE: [Caml-list] SML->OCaml
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2005-03-08 (09:07)
From: Andreas Rossberg <AndreasRossberg@w...>
Subject: Re: [Caml-list] SML->OCaml
Martin Jambon <> 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 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.


  - Andreas