by kjeetgill · 8y ago · 0 comments
I've never worked in a language without parents for function calls so I share their confusion reading Haskell or Ruby code at a glance.
I don't think a language needs to bend for non-users but being intelligible without knowing the language canI be nice.
As an outsider, the examples:
A(B(C)) A(B,C) A(B)(C)
Could all be valid Python but still communicate a little bit about A B and C. Without parents they'd all look like "A B C". I'm sure it's more obvious if you know those languages.
A(B(C)) would be `a (b c)` or `a $ b c` or `(a . b) c`. The first is the most vanilla way, the second is convenience (basically "evaluate everything after $ first, then plug it in") and the third uses the function composition operator `.`.
We can define `$` ("apply a function to an argument") as:
f $ x = f x
We can define `.` ("compose two functions") as (where `\x -> ...` is an anonymous function): f . g = \x -> f (g x)
Equivalents in, say, Javascript would be: function dollar(f, x) { return f(x); }
function dot(f, g) { return function(x) { return f(g(x)); }
People mostly use `$` because of its precedence rules, which cause everything to its left to be treated as its first argument, and everything to the right as its second, i.e. we can use it to remove grouping parentheses like: (any complicated thing) (another complicated thing)
with: any complicated thing $ another complicated thing
It's also useful for partially applying, e.g. `map ($ x) fs` will apply each function in the list `fs` to the argument `x`.No, that would just be a(b,c). You would use parentheses to express the others. a(b(c)) would be a (b c). a(b)(c) would be (a b) c. IMO it's still perfectly readable, you just have to know it and get used to it (which, granted, can be difficult if you're only used to paren-ized languages, but not an impossible ask, certainly not, imo, a deal-breaker).
The latter would be written `a([b, c])` in other languages. These are all isomorphic (we're calling `a` and giving access to `b` and `c`), but can confuse people who are new to the syntax.