caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: skaller <skaller@users.sourceforge.net>
To: Tom <tom.primozic@gmail.com>
Cc: John Carr <jfc@mit.edu>, Caml-list List <caml-list@inria.fr>
Subject: Re: [Caml-list] If OCaml were a car
Date: Mon, 20 Aug 2007 07:45:41 +1000	[thread overview]
Message-ID: <1187559941.6987.40.camel@rosella.wigram> (raw)
In-Reply-To: <c1490a380708191330p404fd12coca61aa2353d6243f@mail.gmail.com>

On Sun, 2007-08-19 at 22:30 +0200, Tom wrote:
> On 19/08/07, John Carr <jfc@mit.edu> 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 <skaller at users dot sf dot net>
Felix, successor to C++: http://felix.sf.net


  reply	other threads:[~2007-08-19 21:45 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-08-18 19:21 Richard Jones
2007-08-18 20:24 ` [Caml-list] " Jeff Meister
2007-08-18 21:32   ` Michael Vanier
2007-08-19 11:50     ` Daniel Bünzli
2007-08-19 11:59       ` Erik de Castro Lopo
2007-08-22  5:50         ` Luca de Alfaro
2007-08-22  8:13           ` Jon Harrop
2007-08-22  9:20             ` Jacques Garrigue
2007-08-24  2:54           ` Nathaniel Gray
2007-08-25 19:45             ` Oliver Bandel
2007-08-19 14:43       ` John Carr
2007-08-19 16:22         ` brogoff
2007-08-19 17:07         ` Richard Jones
2007-08-19 17:19           ` Stefano Zacchiroli
2007-08-22  6:04             ` Luca de Alfaro
2007-08-19 20:51           ` Vincent Hanquez
2007-08-21  8:05           ` David Allsopp
2007-08-21 18:33             ` Richard Jones
2007-08-19 20:30         ` Tom
2007-08-19 21:45           ` skaller [this message]
2007-08-20  3:37             ` Jon Harrop
2007-08-20  6:26               ` skaller
2007-08-20 10:00                 ` Joerg van den Hoff
2007-08-21 12:03                   ` Florian Hars
2007-08-20  6:54               ` skaller
2007-08-20 19:54       ` Oliver Bandel
2007-08-20 20:27         ` David Allsopp
2007-08-20 20:50           ` Ulf Wiger (TN/EAB)
2007-08-21 10:56             ` Joerg van den Hoff
2007-08-20 21:13           ` Oliver Bandel
2007-08-21  0:47         ` skaller
2007-08-21  9:51           ` Oliver Bandel
2007-08-21 10:30             ` skaller
2007-08-21 18:57               ` Richard Jones
2007-08-22  2:49                 ` skaller
2007-08-22 11:33                   ` Thomas Fischbacher
2007-08-21 14:46             ` Business Adoption of Ocaml [was Re: [Caml-list] If OCaml were a car] Robert Fischer
2007-08-21 15:09               ` Brian Hurt
2007-08-21 15:48           ` [Caml-list] If OCaml were a car brogoff
2007-08-19 18:15 [caml-list] " Mike Lin

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=1187559941.6987.40.camel@rosella.wigram \
    --to=skaller@users.sourceforge.net \
    --cc=caml-list@inria.fr \
    --cc=jfc@mit.edu \
    --cc=tom.primozic@gmail.com \
    /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).