> Bringing up an old idea, we could rewrite `rethrows` using Never and throws 
> type specification:
> 
> func call<T, E>(block: () throws E -> T) throws E -> T
> 
> But this requires some compiler magic: non-throwing functions should 
> effectively become functions throwing Never.

This is very clever, and a very natural way to design things *if* Never is a 
proper bottom type, instead of just an empty enum. I don't even think you can 
really describe this as "compiler magic": Just as a function with no return 
type implicitly returns Void, so a function with no throw type implicitly 
throws Never.

(Incidentally, the `E` should be `E: ErrorProtocol`, I believe, since you can 
only throw ErrorProtocols. That's why Never needs to be a proper bottom type: 
it needs to conform to `ErrorProtocol`.)

-- 
Brent Royal-Gordon
Architechies

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

Reply via email to