From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=AWL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from discorde.inria.fr (discorde.inria.fr [192.93.2.38]) by yquem.inria.fr (Postfix) with ESMTP id A743FBC69 for ; Sun, 19 Aug 2007 23:45:51 +0200 (CEST) Received: from ipmail01.adl2.internode.on.net (ipmail01.adl2.internode.on.net [203.16.214.140]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id l7JLjli3007970 for ; Sun, 19 Aug 2007 23:45:50 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAAJ5UyEZ5LGJp/2dsb2JhbAAM X-IronPort-AV: E=Sophos;i="4.19,282,1183300200"; d="scan'208";a="175650197" Received: from ppp121-44-98-105.lns10.syd6.internode.on.net (HELO [192.168.1.201]) ([121.44.98.105]) by ipmail01.adl2.internode.on.net with ESMTP; 20 Aug 2007 07:15:47 +0930 Subject: Re: [Caml-list] If OCaml were a car From: skaller To: Tom Cc: John Carr , Caml-list List In-Reply-To: References: <56864F61-40F3-4F03-9823-6D510AD5320B@epfl.ch> <200708191443.l7JEhEQ8007374@psi-phi.mit.edu> Content-Type: text/plain Date: Mon, 20 Aug 2007 07:45:41 +1000 Message-Id: <1187559941.6987.40.camel@rosella.wigram> Mime-Version: 1.0 X-Mailer: Evolution 2.10.1 Content-Transfer-Encoding: 7bit X-Miltered: at discorde with ID 46C8BA0B.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; ocaml:01 0200,:01 ocaml:01 syntax:01 parser:01 ocaml's:01 syntax:01 elif:01 swapped:01 parses:01 haskell:01 camlp:01 language's:01 haskell:01 sourceforge:01 On Sun, 2007-08-19 at 22:30 +0200, Tom wrote: > On 19/08/07, John Carr wrote: > > OCaml has a badly designed syntax processed by a badly > implemented > parser feeding into a backend that generates poor error > messages. > All this makes the language hard to use. > > I would just like to know, what exactly do you think is badly > designed, and what would be a better alternative? Mind that I am not > defending OCaml's syntax here (I have grown accustumed to it, but I do > not find it superb... probably...), I just think that all criticism > should be constructive (that is, shut up unless you've got a better > idea). I disagree with that: Most analysis is and should be destructive. Understanding problems is the precursor to constructing better solutions. Ocaml has lots of syntactic issues. It has too many operators, so that it is hard to remember their 'precedence'. Some are very un-natural, for example: if e then e1 else e2 The thing is that 'else' has a different 'precedence' than 'then'. So you can write: if e then e1 else a; b; c and a,b,c are all executed if the condition is false, but you cannot write: if e then a; b; c else ... and similarly for let/in. So you need parentheses in the 'then' branch to write a 'larger' expression, but you need parentheses around the whole if/else to write a 'smaller' expression in the else branch .. Furthermore, because of the decision that procedures return unit, you can write: if e then p; without the else, but only if p has type unit: the syntax is so confused it doesn't know if it is functional/expression based (in which case the else expression should be mandatory) or procedural (in which case procedure calls should return void to prevent the call being used as an argument to an application). Felix procedures return void, and it provides if e then e1 else e2 endif // an expression if e do s1; s2; s3; elif e1 then // optional s4; s5; s6; else // optional s7; s8; s9; done; // a statement and in both cases the text of the branches can be transparently swapped around. The cost is additional syntax and the mandatory terminator. But if you don't like it you can roll your own syntax .. as in Ocaml. For example Felix also parses: if (x < 1) print "Less"; else print "No"; // optional if the "C" domain specific sublanguage syntax (DSSL csyntax) is loaded (which it is by default). And if you like Python or Haskell you can even write: if (x < 1) $$ print "Less" else $$ print "No" [the $$ is ugly, but something is required to initiate indent mode] Well it is NOT clear that all these alternatives are actually a good idea, just as it is NOT clear that excess use of camlp4 is a good idea. In my experience, using the language's raw syntax, even if it has warts, is more or less mandatory if you want other people to be able to read your code. Can Ocaml syntax be improved? Yes, but not much. Felix has: print$ "Hello" + " World"; which is stolen from Haskell and gets used a lot. Even if I can implement that with camplp4 I wouldn't. I'd like to see $ in the standard language: then I'd use it. Every 'feature' of Ocaml syntax I hate I also love, for example: let f x = blah blah in WOOPS! I forgot a pre-condition .. let f x = if precond x then specialvalue else blah blah in so I can add just one line without touching the rest of the code .. this is really cool!! .. so maybe the weird if/then/else isn't so bad after all ... :) -- John Skaller Felix, successor to C++: http://felix.sf.net