Pitch: Introduce (static) callables

+1 on the feature from me.

Some comments about the writing:

  • Another motivation is that we have a (long term) goal of unifying structural types and nominal types, to allow structural types to conform to protocols. The natural way to do this is to the structural type be sugar for a named type (just like [Int] is sugar for Array<Int>), so functions will become nominal types at some point (when varargs and a long list of other issues is sorted out, we aren't particularly close to this). When that happens, it would be nice to handle function calls just by virtue of Function having a call member.

  • Grammar thing: "it is uneasy" -> "it isn't easy"

  • Writing: "Machine learning models often represent a function that contains parameters" -> most readers will think that 'parameters' refers to function parameters here, not "learned constants values closed over by the semantic function" :-).

  • " If model could be called like a function, like what it represents mathematically, the code would look much simpler:" -> the key principle we care about here is clarify of the code. I'd recommend pointing out that clarity is really harmed by the lack of this feature.

  • super nit: in sexpParser(“(+ 1 2)”) you have curly quotes going on.

  • Wording, instead of " But it is also very different from subscript in that:" I'd suggest a positive form of "but it is more similar to a func declaration in that:"

  • " A value cannot be implicitly converted to a function when the destination function type matches the type of the call member. While it is possible to lift this restriction, it is beyond the scope of this proposal." -> I'd suggest being more direct and saying something like "implicit conversions are generally problematic in Swift, and as such we would like to get some experience with this base proposal before even considering adding such capability. The explicit support should be enough to unblock any usecase, so that addition is just a sugar"

  • " It guarantees source compatibility." -> This is taking call as a keyword, you should mention that.

Overall, I'm very excited to see this come together, thank you for pushing this forward!

-Chris

8 Likes