> On 9 Jan 2017, at 22:11, Anton Zhilin via swift-evolution > <[email protected]> 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 > )
This is returning an error (or legitimate value) not throwing, yes? Because to me, and most other people probably, throwing is different to returning a legitimate value, not least because the normal control flow is interrupted. Making it look like a return value is confusing and wrong IMO. > > > 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 _______________________________________________ swift-evolution mailing list [email protected] https://lists.swift.org/mailman/listinfo/swift-evolution
