English version
Accueil     Ŕ propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis ŕ jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml ŕ l'adresse ocaml.org.

Browse thread
If OCaml were a car
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2007-08-20 (05:23)
From: Jon Harrop <jon@f...>
Subject: Re: [Caml-list] If OCaml were a car

I'm quite surprised to hear so many non-specific complaints. There are, as 
always, some tweaks I'd like to make...

On Sunday 19 August 2007 22:45:41 skaller wrote:
> 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,

I do not believe this is true. The "b" and "c" are executed in both cases 
because the above is parsed as:

  (if e then e1 else a); b; c

which is syntactically uniform:

# (<:expr< (if true then a else a);b;c >>) =
  (<:expr< if true then a else a;b;c >>);;
- : bool = true

Perhaps you were thinking of this:

  if p then t else
    let () = () in

because "let" binds more tightly.

> 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).

Why should the return value (of unit) not be used as the argument to an 

> 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.

You might prefer the F# operators |>, << and >>.

For syntactic changes, my personal vote goes to some very useful syntactic 
extensions rather than any replacements, and ones that don't (in practice) 
break backward compatibility.

Boolean expressions could permit:

   a < b <= c

Asymmetric whitespace allows a new unary minus operator with higher 

  a - b -> Sub(a, b)
  a -b -> Apply(a, -b)
  a-b -> Sub(a, b)

That's pretty much all I can think of. The rest is fine by me. I'd much rather 
see effort go into an IDE rather than tweaking the syntax and breaking 
backward compatibility.

Dr Jon D Harrop, Flying Frog Consultancy Ltd.
OCaml for Scientists