[swift-evolution] [Pitch] Introduce user-defined dynamically "callable" types

Joe Groff jgroff at apple.com
Sat Nov 11 13:05:37 CST 2017



> On Nov 11, 2017, at 10:52 AM, Xiaodi Wu <xiaodi.wu at gmail.com> wrote:
> 
>> On Sat, Nov 11, 2017 at 12:39 PM, Joe Groff via swift-evolution <swift-evolution at swift.org> wrote:
>> 
>> 
>>> On Nov 11, 2017, at 10:12 AM, Chris Lattner <sabre at nondot.org> wrote:
>>> 
>>> On Nov 11, 2017, at 6:52 AM, Joe Groff via swift-evolution <swift-evolution at swift.org> wrote:
>>>>>> I don't think it's that localized. It's going to make call resolution massively more complicated.  Through great pain and community anguish, we pushed ourselves to a model where argument labels are parts of the declaration name, not part of the call argument, and this would throw us straight back into the kinds of complications of dealing with overloaded name- and type-dependent behavior we're trying to get away from in the language.
>>>>> 
>>>>> I’m pretty sure it doesn’t, but good news: since Swift requires an implementation before the proposal can be officially reviewed, you will be able to look at the actual patch to make this decision.
>>>> 
>>>> And the goal of the pitch phase is to hopefully save you the tears of trying to implement something if it's a bad idea.
>>> 
>>> Appreciated.  Fortunately I enjoy coding so it’s not that big of a deal for me.
>>> 
>>>>>> Swift is a dynamic language too, and tuples have enough metadata in them that you could get almost everything you want with an infix operator.
>>>>> 
>>>>> This is really gross.  The goal here is to make Python feel natural.  If you oppose this proposal then we’ll have to find some other way to provide an elegant experience:
>>>>>> x∫(0, "foo", bar: "bas”)
>>>>> 
>>>>> This is not going to be acceptable to users.
>>>> 
>>>> Is it? My choice of operator character is silly, but it's the same amount of syntactic overhead as an optional chain/force call. It's a fair sight better than x.call(args: ..., keywordArgs: ...), I hope you'd agree, and is something that works without any language change.
>>> 
>>> Yes, I’m happy to explore that, and I agree this approach doesn’t require language changes.  That said, there are three things you should understand:
>>> 
>>> 1) Details matter.  While you claim that there is some other operator character that could be awesome, I’m not seeing it.  Can you try harder to come up with something that you think would be acceptable?
>>> 
>>> 2) The point of the entire proposal is that a certain audience will be using the feature enabled by this (python interop) *a lot*, so ergonomics matter.
>>> 
>>> 3) This feature (python interop) is aimed to get Python programmers to convert to Swift, not simply to ease friction for existing Swift programmers (most of whom are iOS developers, to whom this feature is completely irrelevant).  Getting people to move from Python to Swift is a challenge, and syntax does actually matter. I hope we can agree that expanding the community of Swift developers is a laudable goal.  
>> 
>> Sure. I suggest it not as a final endpoint but as incremental progress you can make with the language today. If you can get some early adopters interested in moving from Python to Swift with some small warts now and the promise of refined syntax in the future, that could let you make progress while we work out the right final model for dynamic language interop.
> 
> As a community member, I have to say that this part of the core team response to the pitch has been the most dismaying part. It is quite evident to all, I'm sure, that the ergonomics and approachability of Python is one of the major draws for its audience. If Python interop in Swift is to gain traction with that audience, it is pretty clear that anything short of `foo.bar(42)` is not going to cut it. Overall, the response to a proposed design to achieve that goal seems to be focused not on the design but on that goal itself, and the gist of the response I'm sensing is "not now, if ever," or "current Swift users first, new Swift users later." If a final model for dynamic language interop is what's necessary before any headway is made in this space, then it would seem to me that it is tantamount to shutting down the conversation here.

I'm sorry for discouraging discussion. I shouldn't have implied that this was a desirable endpoint, I was trying to figure out how far you can get in the language today, and highlight the availability of runtime metadata that could make other approaches more viable than the proposal suggested, and I should've connected those dots more clearly. To be clear, I think this is an interesting problem to solve, and I don't want to shut down conversation. Chris evaluated several approaches and picked one, and it's not the one I would pick. Ultimately, I want to do what's right for the language. I am not "the Core Team" in whole, I'm a single member, and these are my personal opinions not representing the project as a whole. Nonetheless, as a member of the core team, I know my words carry more weight for better or worse, and I'll try to be more careful with them.

-Joe

> 
>> Since you have long term ambitions in this space, I think it'd pay off to consider more infrastructurally-heavy features with bigger long-term payoffs.
>>> 
>>>> You mentioned variadics as being inadequate for your purposes as a considered alternative, but a variadics model that wasn't based on type erasure to arrays and kept runtime type information about the argument tuple that was passed in, along with better reflection APIs for accessing that type info, might lead to something you can use by incrementally improving the expressivity of existing language features instead of adding new ones.
>>> 
>>> I’m not sure what you mean by this: variadics are fine. The hard part is getting the keyword arguments for a call dynamically.  Can you point to what you’re referring to in the proposal?
>> 
>> I was referring to your comment in this section:
>> 
>>> Statically checking for exact signatures
>>> 
>>> This proposal does not allow a type to specify an exact signature for the callable - a specific number of parameters with specific types. If we went down that route, the best approach would be to introduce a new declaration kind (which would end up being very similar to get-only subscripts) since, in general, a type could want multiple concrete callable signatures, and those signatures should participate in overload resolution.
>>> 
>>> While such a feature could be interesting for some use cases, it is almost entirely orthogonal from this proposal: it addresses different use cases and does not solve the needs of this proposal. It does not address our needs because even a variadic callable declaration would not provide access to the keyword argument labels we need.
>>> 
>> We know our variadics model is inadequate in a lot of ways. I was suggesting there are ways of extending it that could allow the 'static' and 'dynamic' callable protocol to be one thing, or have a subscript-like `call` special form.
>> 
>> -Joe
>> 
>> 
>>> -Chris
>>> 
>> 
>> _______________________________________________
>> swift-evolution mailing list
>> swift-evolution at swift.org
>> https://lists.swift.org/mailman/listinfo/swift-evolution
>> 
> 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20171111/2ddebfa7/attachment.html>


More information about the swift-evolution mailing list