[nem-en] Parentheses
Maurizio Colucci
seguso.forever at tin.it
Fri Sep 10 13:17:38 CEST 2004
Hi Kamil,
On Friday 10 September 2004 12:42, Kamil Skalski wrote:
> > > > 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?
> > >
> > > Personally, I am a natural born LISP person :)
> > >
> > > > PS: Even better would be:
> > > >
> > > > List.Map [B()] (fun x -> x.foo);
> > > >
> > > > but I understand this would make too much of a change.
> > >
> > > This looks like partial application to me and we're not supporting
> > > that.
> >
> > No, no, it's not a partial application: Map requires two arguments and
> > two are given. What gave you that impression?
>
> http://www.haskell.org/hawiki/PartialApplication
> Actually partial application is performed here, first [B()] is applied
> to List.Map, resulting in a function, which takes other function as its
> argument and applies it to already supplied list ([B()]). If you write
> full expression like 'List.Map [B()] (fun x -> x.foo)' application is
> performed twice, first [B()] to List.Map, then (fun...) to (List.Map
> [B()]).
Ah, now I see what you mean. But that is not necessary: that is just the way
haskell/ocaml happen to treat that syntax. Nemerle doesn't need to do that. I
mean, you don't need to support the concept of partial application to allow
that syntax. You could even put a preprocessing step that translates
f g (h x);
into
f(g, h(x));
, that is, completely mechanically. That's why I don't understand why Michal
says the ocaml syntax is more ambiguous. To me, there seems to be one-to-one
correspondence.
> Consider following code:
> def f = List.Map [B()] // oops, ; missing here
> bar ();
> foo (f);
>
> You end up with weird error message about appling result of bar () to
> functional value ('a -> 'a) -> list <'a> (the type of List.Map [B()])
Ok, but this only happens in a language that allows partial applications.
Since Nemerle does not, it could give a much more understandable message:
"Map requires two arguments but only one was given".
> This argument is also described in
> http://www.nemerle.org/rationale.html#call-parens
>
> Note, that you can perform partial application in Nemerle by
> fun (f) { List.Map ([B()], f) }
>
> > It was just an attempt to write a ocaml/clean/haskell-like syntax (see
> > the ocaml example above). With this notation, what in nemerle you write
> >
> > f(x, g(x, y, h(z)))
> >
> > becomes
> >
> > f x (g x y (h z))
> >
> > See how much nicer it is to the eye? ;-)
>
> actually I never liked that notation (well, it's my opinion, and
> actually did not like it till I began to fully understand, that it is
> partial application).
Not necessarily...
> And see how error prone and hard to distinguish what exatly is playing
> part of function / argument here.
I agree that is SLIGHTLY more difficult to understand which is the functor and
which is the argument, but you quickly learn, and the ocaml idiom always has
one parenthesis less. Which is much desirable, considering that MOST OF THE
TIME you write things that needs only one parenthesis:
Nemerle:
def x = f(y, z);
ocaml:
let x = f y z;
This is a simplification that really makes your life easier, on the long run.
Consider it takes two minutes to get used to the ocaml idiom, whereas you
have to type parentheses more for the rest of your life. :-)
--
Maurizio Colucci
http://logicaldesktop.sourceforge.net
More information about the devel-en
mailing list