9 ms·
This looks so noisy compared to normal Haskell syntax.
by dunefox 6y ago
This looks so noisy compared to normal Haskell syntax.
- scotty79 6y agoI'd call it verbose. In comparison Haskell syntax seems like a lot of meaning should be magically assumed by default. Sort of like mathematicians tend to do in their notation. Here it's spelled out. 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).
- johnday 6y agoStandard, 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! :)