Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

A B C D is necessarily equal to A(B,C,D) in C-family syntax due to the precedence rules, there is no ambiguity.

The reason whitespace is more elegant is because your functions can return other functions, which due to function currying and partial application is equivalent to your function simply taking more arguments.

I'll use Python as an example.

    def flip(f): return lambda a,b : f(b,a)
That is, it's a function that takes a function of two arguments, and returns a function that does the same thing, but with the argument order flipped.

To use these function, it would look like:

    flip(f)(a,b)
In Haskell, a direct translation with the lambda would be:

    flip f = \a b -> f b a
The type of which could be written as:

    flip :: (a -> b -> c) -> (b -> a -> c)
That is, a function which takes one argument, that argument is a function that takes two arguments of types a and b and yields a value of type c, and returns a function that takes two arguments of types b and a and yields a value of type c.

We could use this function like:

    (flip f) a b
But due to function precedence we could use

    flip f a b
This segues into an equivalent (and arguably better) way to write the function taking advantage of partial application and currying:

    flip :: (a -> b -> c) -> b -> a -> c
    flip f a b = f b a
Which would be used the exact same way:

    flip f a b
This illustrates the elegance of currying.

    a -> b -> c
Is equivalent to

    a -> (b -> c)


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

Search: