Skip to content

[Revision] SE-0253: Introduce callables. #1037

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
May 4, 2019

Conversation

rxwei
Copy link
Contributor

@rxwei rxwei commented Apr 26, 2019

Implementation: swiftlang/swift#24299

Copy link
Collaborator

@lattner lattner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The proposal looks pretty good. In addition to the comments I mentioned above, the proposal should mention that the x.call syntax can be used to refer to the callable in a partially applied way, and this syntax aligns with the Type.init syntax.

@@ -3,8 +3,9 @@
* Proposal: [SE-0253](https://github.com/apple/swift-evolution/blob/master/proposals/0253-callable.md)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The proposal name is very generic, and Swift already has callable things. How about "User Defined Callable Types"?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm intentionally avoiding "callable types" because 1. func call is not restricted to primary type declarations and there's no type declaration attributes, and 2. types being callable sound like initializers.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed the title to "User-defined callable values". What do you think?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't fp a user defined callable value?

var fp : () -> () = {}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good point. How about "non-function callable values"?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Metatypes.

Why not call this "Allowing user defined types to be callable"?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Metatypes are not callable today actually, though I understand in the implementation they are.

let x = Float.self
x(2)
error: repl.swift:2:2: error: initializing from a metatype value must reference 'init' explicitly
x(2)
 ^
 .init

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed it to "Callable values of user-defined nominal types" to be a bit more accurate. Hope that sounds okay to you!

@lattner
Copy link
Collaborator

lattner commented Apr 26, 2019

A few other observations:

  • I'd recommend saying something about how simple and non-invasive the implementation is.

  • "Implicit conversions to function" should mention that you can already explicitly convert them through partial application.

  • I don't think that "static/class call methods" are a likely future direction personally, for exactly the reasons you say. Why not drop that or move to alternatives considered?

  • The first entry of 'alternatives considered' should be other names for this, including "call" "invoke" "apply" or other things that will come up in the thread.

@rxwei
Copy link
Contributor Author

rxwei commented Apr 27, 2019

  • I'd recommend saying something about how simple and non-invasive the implementation is.

Mentioned in the "detailed design" section.

  • "Implicit conversions to function" should mention that you can already explicitly convert them through partial application.

Done.

  • I don't think that "static/class call methods" are a likely future direction personally, for exactly the reasons you say. Why not drop that or move to alternatives considered?

Moved to "alternatives considered".

  • The first entry of 'alternatives considered' should be other names for this, including "call" "invoke" "apply" or other things that will come up in the thread.

Done.

@lattner lattner merged commit 571cadd into swiftlang:master May 4, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants