On Thu, 26 May 2011 07:15:31 +0200, David Griffiths <[email protected]> wrote:

Many, many languages (including Perl, Ruby, VB, Scala, Smalltalk,
Logo, and of course all the ML-like languages, including Haskell and
F#) do without parentheses for calls in some circumstances at least.
Do you use any of these languages? I quite like some of them.

The functional languages (ML-like or Haskell-like) typicallly have curried function
definitions. I.e., if you define a function (ML-syntax, from memory :)
  let fun foo x y z = x * y * z
   in foo 2 3 4
  end;
the function foo isn't actually taking three arguments, it's a curried function of type
 int -> int -> int -> int
taking one argument and returning a new function.


You can also make one argument a product type, so:
  let fun bar (x, y) z = x * y * z
   in bar (2, 3) 4
  end;
defines a function of type (int * int) -> int -> int.

The point is that parentheses are not part of the call syntax at all. It's not that you can omit them in some circumstances. You can omit them in all circumstances, because all functions take only *one argument*. That argument might need to be a tuble, and you use parentheses to create tuples, but they don't need to be part of the call, e.g.
  let fun bar (x, y) z = x * y * z
      val tup = (2,3)
  in bar tup 4
  end;


ECMAScript doesn't curry its function declarations. A function does take all its arguments at once (and not as a tuple value), and since we can even supply too few or too many arguments when calling a function, trying to
mimic SML will only bring pain.

Much as I like SML and Haskell, their function application syntax (literally "exp ::= exp_1 exp_2" [1]) just won't work for ECMAScript. It's pretty in its simplicity, but ECMAScript is long past simplicity on this point.

/L
[1] First match for "SML grammar": http://www.mpi-sws.org/~rossberg/sml.html
--
Lasse Reichstein - [email protected]
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to