[swift-evolution] [Pitch] Never as a bottom type

David Waite david at alkaline-solutions.com
Mon May 15 01:44:15 CDT 2017


> On May 14, 2017, at 11:44 PM, André Videla via swift-evolution <swift-evolution at swift.org> wrote:
> 
>> Joe also referred to the following model in a thread about Typed Throws.
>> 
>>   () -> () == () throws Never -> ()
>>   () throws -> () == () throws Error -> ()
> That makes sense! As a bottom type it would be perfectly fit for this.
> 
>> On 15 May 2017, at 03:01, Robert Widmann <devteam.codafi at gmail.com> wrote:
>> 
>> Though our type lattice doesn’t necessarily have a bottom in the way you’re looking for, you can use Never-returning functions to inhabit a combinator that will do this for you.
> Very useful.
> What do you think of [] as [Never], or nil as Optional<Never>. Can the current inference and subtyping rules deal with that? 

If you mean does this currently compile:

let f:Optional<Never> = nil
let g:[Never] = []

then yes. However, “nil” and “[]” in the above are literals, not types or type instances. They only are used to initialize an instance of a type that is ExpressibleByNilLiteral / ExpressibleByArrayLiteral.

If Never becomes a bottom type, a [Never] or Never? hypothetically could be passed into any function which accepts an array or optional of any type because of covariance and value types, but would always be empty/none version of that type. I can’t think of a practical reason to do this, although I admit I’ve never used a language with a bottom type.

-DW
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170515/0f110512/attachment.html>


More information about the swift-evolution mailing list