3 ms·
> Is there a reason why you would make fn(1) and fn 1 equivalent? For the same reason you'd make 1 + 2 the same as 1 + (2). Parentheses can be used to group ar
by curryhoward 4y ago
> Is there a reason why you would make fn(1) and fn 1 equivalent?
For the same reason you'd make 1 + 2 the same as 1 + (2). Parentheses can be used to group arbitrary subexpressions.
- HelloNurse 4y agoIf fn 1 is an allowed function call syntax then fn (1) should be synonymous because 1 is expected to be the same as (1) except for a slightly different parse tree; but there might be good reasons to make fn 1 not a function call (for example, the implicit operator in a sequence of two expression without parentheses could be string concatenation rather than function application).
- curryhoward 4y ago> the implicit operator in a sequence of two expression without parentheses could be string concatenation rather than function application You can design a language which uses `e1 e2` to represent any binary operation you like, but I'd argue that function application is more common than string concatenation, so it's more deserving of that syntax. Plus, it plays nicely with currying.
- dan-robertson 4y agoI’ve sometimes thought that a reasonable alternate choice would be: f g = composition of f then g x.f = f applied to x x.f g h = in regular notation h(g(f(x)) Though slightly different precedence rules may be preferable. I think the k in awk considered juxtaposition-as-string-concatenation to have been a mistake by the way. Some other reasonable choices may be: - disallowed syntax - multiplication (which, for matrices, is a special case of function composition and application) - inner join which can be seen a bit like function composition but for relations instead of functions - sequencing (ie instead of ‘;’)
- ebingdom 4y agoThat's an interesting idea, but how does it work for functions of multiple arguments? If functions are curried, then I suppose the syntax for `f x y` would be `y.(x.f)`, which maybe you could write as `y.x.f` if the associativity worked as such. But that means you have to provide your arguments in reverse order? If functions are not curried, do you write `(x, y).f`?