From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id PAA12449 for caml-redistribution@pauillac.inria.fr; Wed, 15 Mar 2000 15:07:22 +0100 (MET) Resent-Message-Id: <200003151407.PAA12449@pauillac.inria.fr> Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id JAA11195 for ; Wed, 15 Mar 2000 09:57:03 +0100 (MET) Received: from enst.enst.fr (enst.enst.fr [137.194.2.16]) by nez-perce.inria.fr (8.8.7/8.8.7) with ESMTP id JAA04737 for ; Wed, 15 Mar 2000 09:57:02 +0100 (MET) Received: from email.enst.fr (muse.enst.fr [137.194.2.33]) by enst.enst.fr (8.9.1a/8.9.1) with ESMTP id JAA23969; Wed, 15 Mar 2000 09:56:36 +0100 (MET) Received: from young.enst.fr (young.enst.fr [137.194.34.13]) by email.enst.fr (8.9.3/8.9.3) with ESMTP id JAA29771; Wed, 15 Mar 2000 09:56:35 +0100 (MET) Received: from localhost (debourse@localhost) by young.enst.fr (8.8.8+Sun/8.8.8) with SMTP id JAA09404; Wed, 15 Mar 2000 09:56:35 +0100 (MET) Date: Wed, 15 Mar 2000 09:56:35 +0100 (MET) From: Benoit Deboursetty To: Julian Assange cc: caml-list@inria.fr Subject: Re: let ... in layout In-Reply-To: Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Resent-From: weis@pauillac.inria.fr Resent-Date: Wed, 15 Mar 2000 15:07:22 +0100 Resent-To: caml-redistribution@pauillac.inria.fr > seems such a common construct in caml that it could do with some > syntatic sugar. I often see let..in run to 5-20 clauses. This appears > incredibly ugly compared to the equivalent haskell code, is harder to > read and takes longer to write due to the clutter of the surrounding > token magic. Has anyone thought about applying layout in general to > ocaml, or otherwise sugaring let...in? Is there any reason why the BNF > > let {name = expr}+ in > > would be ambiguous? Plenty... 1. Because the equal sign is also the structural equality operator, there is no way you could know that you begin another binding. With O'CaML now, you can write let a x = f x = 3 which means let a x = ((f x) = 3) where you would like let a x = f in let x = 3 in So perhaps you would better want a reserved keyword such as "be" or "is" to declare bindings. 2. But even there, there is another ambiguity between multiple applications and function definition : think about the following code... let a = f x y z in let g x y z = b in With your proposition this would turn into let a is f x y z g x y z is b in Let us read this as a line : let a is f x y z g x y z is b in \_____________/ where do you separate the two bindings? So, anyway, we must separate two successive bindings with a keyword. Perhaps you want a keyword that is an alias for "in let"... Something you can do sometimes to reduce your number of "let ... in" is to use let a, b, c = ..., ..., ... in (* 3 bindings at a time *) which I believe is optimized by the compilers and finally completely equivalent to let a = ... in let b = ... in ... (except perhaps order of evaluation?) If you do not like O'CaML grammar, I can only encourage you to use the excellent "caml preprocessor and pretty-printer" (camlp4) to modify it. http://caml.inria.fr/camlp4 It is much easier to use camlp4 than to write your own parser!! When you can write both a parser and a pretty-printer for O'CaML and when you can translate automatically from the original syntax to the other and vice-versa, you know you have done something which is not ambiguous. Best regards, BdB.