Treating a Type as a Function

Coincidentally, I was just about to start a thread about treating key paths as function types. Rather than any of the extensible mechanisms you propose here, which are more wide-reaching, I think most of the actual use cases we've been talking about here on this forum lately are covered by making the compiler implicitly convert KeyPath<Base,Value> to (Base) -> Value whenever that is required to type check an expression.

I have implemented such a coercion here: WIP [ConstraintSystem] Ability to treat key path literal syntax as function type (Root) -> Value. by gregomni · Pull Request #19448 · apple/swift · GitHub

This was previously discussed in this older thread: Key path getter promotion

8 Likes