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

Anton Zhilin antonyzhilin at gmail.com
Mon Jan 9 15:11:12 CST 2017

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

let x: (_ a: Int) -> (Error | ())

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170110/c56bcab0/attachment.html>

More information about the swift-evolution mailing list