2
votes

Learning elm but don't get what author means by the below:

The reason we can avoid writing the parenthesis is because function application associates to the left.

2
a b c == ((a b) c); a b c d == (((a b) c) d); a b c = ...body... == a = (\b c -> ...body...) == a = (\ b -> (\c -> ...body...)). - Will Ness

2 Answers

8
votes

Any values or functions, specified after the function name, will be associated with the function as it's arguments automatically, that's really all it means.

In language, like JavaScript, you can explicitly distinguish the usage of a function, as an expression:

function foo (message) {
  return message
}

console.log(foo)          // Function as expression.

console.log(foo('Hello')) // Function application with result: "Hello"

In Elm this behaviour does not require parentesis.

foo message =
  message

foo         -- Function as expression.

foo "Hello" -- Function application with result: "Hello"

It's not like in JavaScript at all, when you want to apply the function and do something with result. Here you will have to tell the compiler explicitly, that (foo "Hello") is a single argument for String.toUpper

String.toUpper (foo "Hello") -- "HELLO"
2
votes

The parentheses in question is ((divide 5) 2). My interpretation of that sentence is that you can write ((divide 5) 2) as divide 5 2 because divide 5 2 is evaluated from the left first, i.e. divide 5 -> divide5 then divide5 2 -> 2.5.

Though I can't see how else it could be evaluated! Neither 5 2 nor divide 2 then divide2 5 make sense.