4 ms·
Standard, base Haskell admits the following definition: let f lst = lst & map normalize & filter (\x -> x > 0) & a
by johnday 6y ago
Standard, base Haskell admits the following definition:
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...)
- gavinray 6y agoI have almost no Haskell experience, but I was playing around in GHCI the other day and it seems you can add parens to function arguments if you want? 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]
- marcosdumay 6y ago> you can add parens to function arguments if you want? 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.
- gavinray 6y agoIt seems kind of weird coming from other languages to not visually distinguish the function call from the arguments if you have the option. 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.
- marcosdumay 6y agoSpace is the symbol that denotes a function call in Haskell. 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.
- tromp 6y agofilter ( > 0) also works.
- lalos 6y agoFor non-haskellers '&' is the reverse application operator.
- scotty79 6y agoSure. But it's more important what people do than what's possible.
- johnday 6y agoI addressed this point precisely in the edit! :)