[swift-evolution] 'T != Type' in where clause

David Sweeris davesweeris at mac.com
Wed Mar 1 11:27:29 CST 2017

> On Feb 28, 2017, at 09:38, Adrian Zubarev via swift-evolution <swift-evolution at swift.org> wrote:
> I also thought about the Either type.
> enum Either<A, B> where A != B {
>     case -> A
>     case -> B
> }

I was thinking about using it as a workaround for not having typed throws:
protocol MyErrorType: Error {...} // all my custom errors conform to this
enum MyError<T: MyErrorType, U: Error> : Error where !(U: FixableError) {
    case myError(T)
    case otherError(U)

Which ensures that, if an instance of "MyError" is .otherError, the payload will actually be an other error (or at least not an error that originated with any of my code).

Seems like if the program logic is intended to ensure that something is only a value of an exact type and not some sort of subtype, there ought to be a way to express that to the type system.

- Dave Sweeris
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170301/a8866387/attachment.html>

More information about the swift-evolution mailing list