[swift-evolution] Bool vs. Optional<Void>
Andrew Bennett
cacoyi at gmail.com
Thu Dec 17 05:11:30 CST 2015
Interesting proposal, I think there's value in exploring this, it certainly
seems logical. I'd like to see the impact on an existing codebase and if
there's any savings/conveniences/issues.
My main concerns, mostly that Swift is not yet ready for it:
* How does this compare semantically when used in an if/guard statement?
* If higher kinded types are introduced should "Optional<Int>" be of a
kind with "Bool" ?
* Optional casting rules need some work still, in my opinion.
* How does this relate to "ImplicitlyUnwrappedOptional<Void>" ? they seem
sometimes interchangeable with "Optional<Void>".
* As you mentioned, but in more detail:
+ Making it conform to "BooleanType", "BooleanLiteralConvertible" is
not yet possible:
*error: same-type requirement makes generic parameter 'Wrapped' non-generic*
extension Optional where Wrapped == Void { /*...*/ }
+ Can we, or even should we specialise debugDescription for
CustomDebugStringConvertible ?
* Assuming the generic is equivalent to this:
enum Bool: BooleanType, BooleanLiteralConvertible {
case Some()
case None
}
+ Will that be optimised to the same extent as Bool?
+ Will it be packed as efficiently as Bool (Int1)?
+ Is "let myBoolean = .None" confusing? should it be allowed?
On Thu, Dec 17, 2015 at 9:25 PM, Brent Royal-Gordon via swift-evolution <
swift-evolution at swift.org> wrote:
> This is less a proposal and more a vague notion, but here goes.
>
> Occasionally, Optional<Void> comes up in Swift. This particularly happens
> with optional chaining (and its socially awkward twin
> `Optional.flatMap(_:)`), but I occasionally see it come up in other places,
> particularly where you’re using a Result-ish type. Wherever it does come
> up, it seems to have the same semantic meaning as Bool, with `nil` meaning
> `false` and `()` meaning `true`.
>
> Does it make sense to somehow unify them? Perhaps turn Bool into a
> typealias for Optional<Void> and move all of its conformances into (not yet
> supported) conditional conformances on Optional?
>
> --
> Brent Royal-Gordon
> Architechies
>
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20151217/ba353fac/attachment.html>
More information about the swift-evolution
mailing list