It should be possible to declare a function that returns only nil, and have its return type be substitutable for any function that returns and Optional. This is something like having a bottom type but not really. What I mean is:
func returnsNil(errCode:Int) -> nil {
logError(errCode) // A side-effect. Not FP, sosumi.
return nil
}
func returnAOptional() -> A? {
// Bla bla. We discover an error so we decide to bail and return nil.
return returnsNil(errCode) // Would be legal.
}
func returnsBOptional() -> B? {
// Bla bla. We discover an error so we decide to bail and return nil.
return returnsNil(errCode) // Would also be legal.
}
I seek a return type that conforms to any Optional -- I think that implies it *must* (or correct me here) be nil.
Now perhaps this is already possible with wizardry from the Next Level. (There always is one.)
On Jan 3, 2016, at 10:43 PM, Andrew Duncan via swift-evolution <swift-evolution@swift.org> wrote:
It should be possible to declare a function that returns only nil, and have its return type be substitutable for any function that returns and Optional. This is something like having a bottom type but not really. What I mean is:
func returnsNil(errCode:Int) -> nil {
logError(errCode) // A side-effect. Not FP, sosumi.
return nil
}
func returnAOptional() -> A? {
// Bla bla. We discover an error so we decide to bail and return nil.
return returnsNil(errCode) // Would be legal.
}
func returnsBOptional() -> B? {
// Bla bla. We discover an error so we decide to bail and return nil.
return returnsNil(errCode) // Would also be legal.
}
I seek a return type that conforms to any Optional -- I think that implies it *must* (or correct me here) be nil.
Now perhaps this is already possible with wizardry from the Next Level. (There always is one.)
On Jan 3, 2016, at 10:43 PM, Andrew Duncan via swift-evolution <swift-evolution@swift.org <mailto:swift-evolution@swift.org>> wrote:
It should be possible to declare a function that returns only nil, and have its return type be substitutable for any function that returns and Optional. This is something like having a bottom type but not really. What I mean is:
func returnsNil(errCode:Int) -> nil {
logError(errCode) // A side-effect. Not FP, sosumi.
return nil
}
func returnAOptional() -> A? {
// Bla bla. We discover an error so we decide to bail and return nil.
return returnsNil(errCode) // Would be legal.
}
func returnsBOptional() -> B? {
// Bla bla. We discover an error so we decide to bail and return nil.
return returnsNil(errCode) // Would also be legal.
}
I seek a return type that conforms to any Optional -- I think that implies it *must* (or correct me here) be nil.
Now perhaps this is already possible with wizardry from the Next Level. (There always is one.)
On Jan 3, 2016, at 10:43 PM, Andrew Duncan via swift-evolution <swift-evolution@swift.org <mailto:swift-evolution@swift.org>> wrote:
It should be possible to declare a function that returns only nil, and have its return type be substitutable for any function that returns and Optional. This is something like having a bottom type but not really. What I mean is:
func returnsNil(errCode:Int) -> nil {
logError(errCode) // A side-effect. Not FP, sosumi.
return nil
}
func returnAOptional() -> A? {
// Bla bla. We discover an error so we decide to bail and return nil.
return returnsNil(errCode) // Would be legal.
}
func returnsBOptional() -> B? {
// Bla bla. We discover an error so we decide to bail and return nil.
return returnsNil(errCode) // Would also be legal.
}
I seek a return type that conforms to any Optional -- I think that implies it *must* (or correct me here) be nil.
Now perhaps this is already possible with wizardry from the Next Level. (There always is one.)
On Jan 3, 2016, at 10:43 PM, Andrew Duncan via swift-evolution <swift-evolution@swift.org <mailto:swift-evolution@swift.org>> wrote:
It should be possible to declare a function that returns only nil, and have its return type be substitutable for any function that returns and Optional. This is something like having a bottom type but not really. What I mean is:
func returnsNil(errCode:Int) -> nil {
logError(errCode) // A side-effect. Not FP, sosumi.
return nil
}
func returnAOptional() -> A? {
// Bla bla. We discover an error so we decide to bail and return nil.
return returnsNil(errCode) // Would be legal.
}
func returnsBOptional() -> B? {
// Bla bla. We discover an error so we decide to bail and return nil.
return returnsNil(errCode) // Would also be legal.
}
I seek a return type that conforms to any Optional -- I think that implies it *must* (or correct me here) be nil.
Now perhaps this is already possible with wizardry from the Next Level. (There always is one.)
On Jan 3, 2016, at 10:43 PM, Andrew Duncan via swift-evolution <swift-evolution@swift.org> wrote:
It should be possible to declare a function that returns only nil, and have its return type be substitutable for any function that returns and Optional. This is something like having a bottom type but not really. What I mean is:
func returnsNil(errCode:Int) -> nil {
logError(errCode) // A side-effect. Not FP, sosumi.
return nil
}
func returnAOptional() -> A? {
// Bla bla. We discover an error so we decide to bail and return nil.
return returnsNil(errCode) // Would be legal.
}
func returnsBOptional() -> B? {
// Bla bla. We discover an error so we decide to bail and return nil.
return returnsNil(errCode) // Would also be legal.
}
I seek a return type that conforms to any Optional -- I think that implies it *must* (or correct me here) be nil.
Now perhaps this is already possible with wizardry from the Next Level. (There always is one.)