Re: Language improvements (?)

Frank Christoph (christo@nextsolution.co.jp)
Wed, 24 Jul 1996 18:53:44 +0900

Date: Wed, 24 Jul 1996 18:53:44 +0900
From: christo@nextsolution.co.jp (Frank Christoph)
Message-Id: <9607240953.AA00610@sparc3.nextsolution.co.jp>
To: Pierre.Weis@inria.fr
In-Reply-To: <199607240844.KAA21840@pauillac.inria.fr> (message from Pierre Weis on Wed, 24 Jul 1996 10:44:17 +0200 (MET DST))
Subject: Re: Language improvements (?)

> I don't know exactly what you mean by a ``symbolic identifier'', if
> you mean an identifier entirely made of characters that are not
> letters or parens (e.g. ++ or <=> or >>), then Caml support it.

Sorry, I just noticed that myself after looking at the sources. Maybe it
should be mentioned more prominently and under the same heading as identifiers
in the lexical conventions section of the manual. It's sort of easy to miss
it as the last part of the last sentence under the "Prefix and infix symbols"
heading: "... but otherwise behave much as identifiers." I also noticed that
you cannot use such identifiers as method names, which makes sense as the
language stands now, but if you were able to syntatically separate method
invocations from their objects (owners), infix or prefix methods would be
sensible. (Granted, I don't know if that suggestion was workable or not.)

>> Third, since the trend in O'Caml is toward curried function types, it would
>> be useful to be able to section binary operators as in Haskell, e.g., "(1+)"
>> would mean "(function x -> 1 + x)".
>
> Wao! Is this so useful ?

If you get in the habit of defining symbolic identifiers it is. Judging
from how often I see people write "leq" instead of something like "(<==)" (not
"<=", to avoid the keyword), I guess this is not so common in the ML world.
Anyway, it's a trivial extension, and it allows you to curry symbolic
identifiers in the same way as conventional identifiers.

>> And, at the risk of instigating a syntax war, I would prefer a more
>> Haskell-like syntax overall; for example, offside scoping,
>
>By ``offside scoping'', you mean a ``where'' construct, I presume ?

No, although that would be nice too. :) I mean an indentation convention
for lexical scoping. For example, instead of

if x = y then (do_a; if x = z then do_b) else do_the_other_thing

write:

if x = y then do_a;
if x = z then do_b
else do_the_other_thing

Here the lexical analyzer can determine that the else-clause belongs to the
first "if" because the position of the "else" is to the left of the second
"if" (off-side) and thus must belong to an outer scope.

Most people will not be convinced by this example because dangling if's
don't occur that often in practice, esp. in a mostly-functional language, but
it also helps in nested match's and let's, etc. This convention enforces a
certain style of formatting, it's true, but it's a good style, and very
readable.

The two major problems with the convention are easy to fix. First, it makes
it more difficult to generate programs automatically because scoping is more
subtle. You can fix this by mandating that the convention is not in effect
between an explicit "begin" and an "end". (This requires some small
adjustments to the syntax, I suppose, like changing "sig ... end" to "sig
begin ... end".) The second problem is more or less a non-issue in Objective
Caml. In Haskell, modules need to start with an explicit declaration "module
ModuleName where ..." (oh, is this what you meant by "where"?) which would
mean that, if the entire file is one module, all subsequent lines would need
to be indented at least one space. This can be fixed by adopting the
convention that the first line of a file is considered to have a "negative"
indentation, or something similar. In O'Caml the compiler inserts the
module declaration for you, so it's not a problem.

Most people indent their code anyway, so off-side scoping just helps to
eliminate syntax noise. Also, it helps prevent mistakes (like forgetting to
delimit nested match's, as I said, which I have gotten caught in more than
once now). The convention is easy to get used to, and, for me, it was so
successful in Haskell that I really miss it in O'Caml.

------------------------------------------------------------------------
Frank Christoph Next Solution Co. Tel: 0424-98-1811
christo@nextsolution.co.jp Fax: 0424-98-1500