Why don't some functional languages โ€‹โ€‹use parentheses for function arguments?

I am trying to adapt a functional language to my program. I am using C # and rely heavily on LINQ and other functional constructs. I am currently focusing on Elm.

One thing that continues to bother me is the lack of parentheses in functions. Mathematical expressions use them:

f(z) = ln(z) + 1

      

However, in many functional languages โ€‹โ€‹this is written as:

f z = ln z + 1

      

Is this just a thing of style or is there something deeper here?

+3


source to share


3 answers


Functional languages โ€‹โ€‹are embedded in lambda calculus that do not use parentheses for a functional application.

It's a syntactic thing, of course, but the way these functions are applied makes sense to leave the parentheses aside, since a function with two arguments first applies the leftmost argument of the function and outputs the function that is used as the second argument.For example, for the function you're used to:

add(x,y) { return x + y } 

      

in functional terms



add x y
add :: Int->Int->Int

      

where the intermediate step after applying x returns another function

add 4  -- returns a function that will return 4 + y, when y is applied
add 4 :: Int->Int

      

To a certain extent, this helps to avoid confusion with the programming languages โ€‹โ€‹you are used to, where add (4) can cause an error. He reads more like mathematics with associativity ((add x) y)

.

+3


source


One of the reasons to avoid parentheses in a function app is currying .

If you code f x y

(as in Ocaml), then f x

it's just curryfication. If you don't have such notation, you need an explicit lambda (or some anonymous function ) like in the diagram(lambda (y) (f x y))



On the other hand, languages โ€‹โ€‹with currying are often implicitly interpreted f x y

as (f x) y

, and then their implementation must optimize this to avoid creating useless temporary closures .

I have mixed feelings wrt Dressing. This may not be useful often (but you need it sometimes), and perhaps the short anonymous function notation is sufficient

+3


source


Contrary to the notation we see, this affects my math, and I've seen at least two types of function notation in mathematics to show the domain to the mapping of the code.

f (x) = x + 1 and x โ†’ x + 1

So, I think maybe languages โ€‹โ€‹without brackets are derived from a later one, maybe

-1


source







All Articles