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 | ())

​
_______________________________________________
swift-evolution mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-evolution

Reply via email to