Hacker News new | past | comments | ask | show | jobs | submit login

Most functional languages parse a b c d e f as a(b, c, d, e, f), it does not matter what b, c, d, e, f are. Do you know any language where this is different?



No functional languages do that.

OCaml parses a b c as ((a b) c). In case the compiler can determine that a is a function taking 2 arguments, it will optimise the code, so that it’s effectively a(b, c). But in general, that’s not possible, especially in the case where the compiler determines that a is a function with a single argument (in which case, it’s return value must be another function, which is in turn called with c) or when a is a first-class function (e.g. passed as an argument)


My toy FP language did. :) It’s perfectly possible to just parse a list of arguments and figure out currying in a later compiler stage. In my experience it even somewhat helps with producing nicer arity-specific error messages, which user might appreciate.


OCaml and Haskell parse `a b c d e f` as `((((a b) c) d) e) f`.


And while different than Algol-descended languages, I don't think that's particularly confusing. (Not that you were saying so, just continuing the conversation.) You can put together a confusing expression with it, but I can put together confusing things with the Algol syntax with not too much effort too. I've got the source code with my name on the blame to prove it.


I thought more languages did this but at least nix and ocaml do not actually behave like I thought.

In Ruby however it is a bit more ugly

  def f x
    x + 1
  end

  puts f f 1
> 3


I don't understand your objection, what output would you like to see instead?


GP's point is that while yes, we know since `f` has arity 1 there's no ambiguity, in general you might not have the arity of any given function fresh in your head, and therefore can't tell (in Ruby) just from looking at `f f 1` whether it means a single invocation of an arity 2 function, or two invocations of an arity 1 function


Ah! Right. It helps to have all functions be of arity 1 to disambiguate, yes.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: