[nem-en] Parentheses

Michal Moskal malekith at pld-linux.org
Wed Sep 8 17:23:22 CEST 2004


On Wed, Sep 08, 2004 at 09:35:41AM +0200, Maurizio Colucci wrote:
> Hello,
> 
> With the ongoing update to the type inference (I read the Monologue :-)), the 
> only thing that is holding me back from using Nemerle (instead of ocaml) is 
> the heavy notation with too many parentheses, especially for lambdas: 
> 
> Nemerle:
> 
> List.Map ([B()], fun (x) { x.foo });
> 
> Ocaml:
> 
> List.map [new B]  (fun x -> x#foo)

(fun x -> x#foo) vs fun (x) { x.foo } is exactly one keystroke shorter.
Haskell's (\x. x.foo) would be better ;-)

Leaving jokes behind: there are reasons to use parentheses in a
,,heavy'' fashion. First of all the syntax is less ambiguous, more
explicit, which in turn means that it is easier to understand, at for the
compiler, but probably also for most programmers around.

Better understanding by the compiler means that more errors are detected
during parsing, and not during typing, like in OCaml.

As for humans. I also found it somewhat ugly in the beginning (Nemerle
used to look much more like OCaml a year ago). But then I used to it. At
least it is consistent -- curly braces everywhere :-)

> I understand the syntax is meant to be similar to C#, but this should be taken 
> into consideration. Does nobody feel this as a problem?
> 
> IMHO the problem would be easily fixed by allowing this alternative syntax for 
> lambdas (in addition to the current one):
> 
> List.Map ([B()], fun x -> x.foo );
> 
> Would this be possible?

Maybe it will be possible to easily change syntax of the entire
language, when the new parser is implemented. Parser will then have much
less core and much more macros. Kamil? 

> PS: Even better would be:
> 
> List.Map [B()]  (fun x -> x.foo);
> 
> but I understand this would make too much of a change.

Partial application is:
  a) hard to understand, 
  b) can cause function not to be called at all, when an argument is
     forgotten,
  c) is hard to use with overloading, consider overloading in Haskell,
     where overloaded functions need to have types of the same ,,shape''.

> PPS: And what about removing () from B()?

B is a functional value of type void -> B. So the usage of () is simply
consistent with the rest of the language.

-- 
: Michal Moskal :: http://www.kernel.pl/~malekith :: GCS !tv h e>+++ b++
: ::: Logic is a nice contrast to the Real World. :: UL++++$ C++ E--- a?




More information about the devel-en mailing list