[swift-evolution] Move placement of 'throws' statement

Tyler Cloutier cloutiertyler at aol.com
Tue Jan 10 03:28:31 CST 2017

> On Jan 9, 2017, at 1:11 PM, Anton Zhilin <antonyzhilin at gmail.com> wrote:
> I also thought about sum types as implementation of errors, but selecting between Tyler’s and John’s syntaxes, I would pick the latter. Compare:
> let x: (_ a: Int) -> (Error | (_ b: Float) -> (Error | Double))
> let x: (_ a: Int) throws(Error) -> (_ b: Float) throws(Error) -> Double
> let x: (_ a: Int) -> (Error | Double)
> let x: (_ a: Int) throws(Error) -> Double
> Granted, the version with sum types contains less characters and leads to more minimalistic type system. But | on itself does not mean error handling. It’s used for creation of sum types, without error handling semantics. So it’s easier to grasp the meaning of type containing throws than anything else. If Swift had a special symbol as related to errors, as ? relates to optionals, then we could use it there. Unfortunately, there isn’t anything like that.
> What would it look like if the function returns nothing but can throw an error?
> let x: (_ a: Int) -> (Error | ())

Or even possibly just
let x: (_ a: Int) -> Error
depending on your tastes.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170110/2549a299/attachment.html>

More information about the swift-evolution mailing list