Like in the example of
f = average . filter (> 0) . map normalize
vs let f(lst) = lst.map(normalize)
.filter((x) => x > 0)
.average
In the second version I can clearly see that I'm creating a function that is supposed to take one argument. It even has a name that might indicate what I'm expecting.Don't get me wrong. All the required information is there but some of it is "written between the lines".
Sort of like CoffeeScript which people tend to hate (and I love, just because I understand JS perfectly and in comparison to CoffeeScript it looks noisy for me).
let f lst = lst
& map normalize
& filter (\x -> x > 0)
& average
Which is barely different from your second presentation. (EDIT: just in case you think I'm ass-pulling here, this is fairly idiomatic code that I'd certainly write in prod! See another comment I posted earlier this week...)Nobody seems to add parens to separate arguments from function calls though in Haskell, never seen it but it works.
let f(lst) = lst
& map normalize
& filter (\x -> x > 0)
& average
Prelude Data.Function> let f(lst) = lst & map (\x -> x + 2) & filter (\x -> x > 4)
Prelude Data.Function> f([2,3,4])
[5,6]Of course. This "(x)" and this "x" are the same. You can put any expression inside parenthesis. Haskell also has tuples, that you write as "(a, b, c)" and can use as a function parameter.
There is even some functions in base for converting functions that receive a tuple into functions that receive many parameters and the other way around.
Nobody in Haskell does this (to the point I had no idea it could be done until I tried it) so clearly it's something you get used to, but boy does it look real alien to me.
It is indeed different from other languages, that require an argument list in parenthesis. It can be different because values and functions are not ambiguous on Haskell; there isn't such thing as a function with no argument.
filter ( > 0)
also works.