For more intuition on the difference between Void
and Never
, consider a function with no return declaration. It is not strictly non-returning, although often named such, but rather void-returning. I guess one could call it a no value-returning function.
func foo() { }
It returns, so therefore it returns something, but that something is kinda like nothing. It is something with no information. The global singleton, which means everything and nothing.
In a sense, Never
is loading more information than Void
.
I think it is possible to infer default generic type parameters by providing a default value to an initializer now:
struct Product<A, B> {
var a: A
var b: B
init (a: A, b: B = ()) {
self.a = a
self.b = b
}
}
let p = Product(a: 10) // inferred as Product<Int, Void>
p.b // returns (), aka no additional information.