[swift-evolution] [Idea] Repurpose Void

Dave Abrahams dabrahams at apple.com
Mon Apr 25 17:15:47 CDT 2016


on Sat Apr 23 2016, Антон Жилин <swift-evolution at swift.org> wrote:

> SE-0066 disallows Void to be used on left side of function types.
>
> Some people, including me, argue that Void should be removed altogether,
> because:
> 1) () is more consistent with curried functions: (Int) -> () -> Double
> 2) () follows functional programming traditions
>
> Now, why don't we repurpose Void to follow functional programming traditions as
> well?
> Its definition will look like:
> enum Void { }
>
> Basically, Void is a type which cannot have values.
> With it, we can eliminate at least two Swift special cases:
>
> 1. Noreturn functions
>
> func exit(code: Int = 0) -> Void
>
> From this signature, it's obvious that `exit` cannot return normally
>
> 2. Rethrows
>
> func call<T, U>(block: () throws T -> U) throws T -> U
>
> Non-throwing functions are functions throwing Void.
> So if T=Void, we get the non-throwing version of `call`.

Repurposing the name "Void" in this way would move Swift definitively
away from being a C-family language.  If we were to do that, we should
do it very consciously and with full awareness of the larger
implications.  I.e. this isn't just about one name.

-- 
Dave



More information about the swift-evolution mailing list