[swift-evolution] [Idea] Allow more operators as custom operators

Антон Жилин antonyzhilin at gmail.com
Mon Apr 11 01:35:45 CDT 2016


Thank you Brent!
I forgot about the cases you described, where use of `->`, `!` or `?`
cannot be expressed as operator functions.
The question is closed now, I guess.

- Anton

2016-04-11 9:03 GMT+03:00 Brent Royal-Gordon <brent at architechies.com>:

> > `->`, `?` and `!` are used in types, but they are mostly unambiguous in
> expressions.
>
> Sure, but types can appear in the middle of expressions. If we drop the
> `.self` requirement, a type name will *be* an expression. I don't think you
> can just ignore type names.
>
> > The only use of `!` in expressions can be rewitten as a built-in
> operator function:
> > postfix func ! <T> (left: T!) -> T
>
> This doesn't work because you can assign through an `!`. For instance:
>
>         numberDictionary[key]! += 1
>
> Once we have inout return values, we might be able to make `!` a normal
> postfix operator. (Actually, the same goes for `&`, which just becomes a
> way to leverage the implicit `&`ing of operator arguments into an explicit
> `&`ing.)
>
> > `?` is used in optional method calls:
> > a.method?(b)
> > A parallel proposal is going to remove such syntax from Swift, so this
> will not be a problem.
>
>
> `?` is used for a lot more than that in expressions: optional chaining,
> the ternary operator, etc. None of them can be expressed as ordinary
> operators without significantly expanding operator syntax.
>
> Sorry, I don't think we can make any real progress in this space without
> additional language features.
>
> --
> Brent Royal-Gordon
> Architechies
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160411/3d7abca7/attachment.html>


More information about the swift-evolution mailing list