What is your evaluation of the proposal?
I do feel like we're loosing semantic clarity about what is a function and I don't find the example very convincing.
Is the problem being addressed significant enough to warrant a change to Swift?
Personally, I don't feel the need for this. I'm quite happy making closure and passing around function types. I'm not too fond of the idea of "values representing functions" that aren't function types. I like to have clear lines between some concepts instead of "everything can act like anything".
I find it makes little sense to be able to "call" a Parser
, or "call" a Model
, or "call" a Polynomial
. The goal of these examples seems entirely about saving some typing at the call site, but you can already bind the function you want to a variable:
let eval = Polynomial(coefficients: [2, 3, 4]).evaluated
print(eval(2)) // => 24
Perhaps if the syntax for declaring this wasn't called call
I'd be more inclined to accept the non-call use cases. Something more operator-like such as func ()(param: Int)
comes to mind, where ()
acts as an operator name like in func ==(a: Int, b: Int)
.
I also worry about this being later allowed on metatypes later and it becoming confusing with an initializer call. Although I don't think this is part of this proposal.
Does this proposal fit well with the feel and direction of Swift?
I'm a bit puzzled about how this interacts (or not) with SE-0111 which removed the type system significance of function argument labels in function types. It was hinted at the time that variables of a function type would eventually get "compound names", allowing the labels to become part of the variable's name.
There's no way I can see compound names work with static callables though. Argument names and overloading in call
makes static callable types fundamentally different from a function type.
So I'm not too sure where this new feature would lead us to in term of consistency. It seems to me static callables are moving back to the old days where argument labels were part of the type. Should we revert some parts of SE-0111 to improve consistency?
Or perhaps we could make argument names non-significant in call
(like they are for operators) which would allow callable types to have compound names. That would also require forbidding overloading for call
or else the compound names would make no sense. That'd bring callable types closer to a function type.
If you have used other languages or libraries with a similar feature, how do you feel that this proposal compares to those?
C++ has operator()
which is quite similar to this and allows one to write functors. I mostly stopped using functors in C++ as soon as lambdas appeared (C++ name for a closure). I still have to use them for some APIs that expects to be passed functors to be overloaded (or templated) by argument type like a visitor pattern made entirely static through templates (which wouldn't work in Swift).
D has opCall
which to my knowledge is pretty much always used in conjunction with static
to work around limitations of struct constructors.
How much effort did you put into your review? A glance, a quick reading, or an in-depth study?
Read the proposal, most of the review thread, and gave it some thought.