From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Delivered-To: caml-list@yquem.inria.fr Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by yquem.inria.fr (Postfix) with ESMTP id EB769BC32 for ; Tue, 8 Mar 2005 10:07:57 +0100 (CET) Received: from smtp07.web.de (smtp07.web.de [217.72.192.225]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id j2897vRp021128 (version=TLSv1/SSLv3 cipher=EDH-RSA-DES-CBC3-SHA bits=168 verify=NO) for ; Tue, 8 Mar 2005 10:07:57 +0100 Received: from [217.83.19.105] (helo=wiko) by smtp07.web.de with smtp (WEB.DE 4.103 #192) id 1D8ah3-0003pE-00 for caml-list@yquem.inria.fr; Tue, 08 Mar 2005 10:07:57 +0100 Message-ID: <005701c523be$d1997260$14b2a8c0@wiko> From: "Andreas Rossberg" To: References: Subject: Re: [Caml-list] SML->OCaml Date: Tue, 8 Mar 2005 10:11:16 +0100 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2800.1437 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441 Sender: AndreasRossberg@web.de X-Sender: AndreasRossberg@web.de X-Miltered: at nez-perce with ID 422D6B6D.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; rossberg:01 caml-list:01 ocaml:01 sml:01 violate:01 ocaml's:01 parsing:01 syntax:01 sml:01 bindings:01 lowercase:01 constructors:01 implicitly:01 sig:01 val:01 X-Spam-Checker-Version: SpamAssassin 3.0.2 (2004-11-16) on yquem.inria.fr X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.0.2 X-Spam-Level: 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 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