> 1) For noreturn, the core team prefers to explore a solution where a function
> can be declared as returning an non-constructable “bottom” type (e.g. an enum
> with zero cases). This would lead to something like:
>
> func abort() -> NoReturn { … }
>
> This will require some new support in the compiler, but should flow better
> through the type system than @noreturn in function composition and other
> applications. Joe Groff offered to write a proposal for this.
Are you thinking in terms of a *real* bottom type—that is, a type which is the
subtype of all types—or a fake bottom type which is simply an empty enum?
If you're thinking about a real bottom type, I wouldn't want to call it
`NoReturn`, because the bottom type may end up playing a larger role in the
language. Given our use of `Any`, the natural names for a bottom type are
probably `All` (as the subtype of all types) or `None` (as a type with no
instances). I do worry that those names are a little too short and attractive,
though. `None` might be mistaken for `Void`; `All` might be mistaken for `Any`,
and wouldn't make much sense when read as the return value of a function.
My best suggestion is `Never`. A function with a `Never` return type would read
as "never returns":
func abort() -> Never { … }
If it appeared in, say, a generic type, it would mean "never occurs":
let result: Result<String, Never>
Flowing from that, we can end up with functions taking a `Never` parameter,
which are never called:
result.flatMapError { (_: Never) in fatalError("can't happen") }
Or `Never?` values, which are never `some`:
let _: Never? = Result<String, Never>.error
(By the way, the return type of the force unwrap operator on a `Never?` is
`Never`, which is just right: if you force unwrap a `Never?`, it will always
trap, never return.)
The main issue I see with `Never` is that it's an adverb, not a noun. But the
nouns all seem to have problems. And besides, the bottom type isn't so much a
thing as a lack of a thing, isn't it? That's bound to have a slightly funky
name.
--
Brent Royal-Gordon
Architechies
_______________________________________________
swift-evolution mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-evolution