[swift-evolution] [Idea] Repurpose Void

Антон Жилин antonyzhilin at gmail.com
Sat Apr 23 19:01:53 CDT 2016

SE-0066 disallows Void to be used on left side of function types.

Some people, including me, argue that Void should be removed altogether,
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`.

- Anton
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160424/173c9d54/attachment.html>

More information about the swift-evolution mailing list