I agree that swift functions are unbalanced: we are permitted to have zero arguments, but we are required to always have at least one return (even if it is of type Void). This is indeed an inconsistency that I have even noted myself. However, my argument is from the other angle: why can we not truly have a no return function: func noArgNoReturn()
should not return even void. To me this would be the better option as far as symmetry is concerned. Both sides would then have the ability to contain 0 to n elements. I am curious to your's and @hooman's thoughts are on this.
The other problem I see, is that you are asking for the type Void
be allowed to equal whatever type T
becomes at compile time. Again, this also goes completely against the type safety that has progressively been put into place over each version. Great lengths have been made to limit the use of Any and AnyObject in favor of explicit types. I believe that could even be said regarding the generic types. While they don't have an actual inherent type when you're writing your code, they do expect T
to not be A
to not be U
or however many generics are available in that signature. For Void
to allow T
or A, B
, etc. is certainly very C, but it is not very Swift.
func noArg() -> ()
func oneArg<T>(T) -> ()
func takesNoArgFunc(() -> ()) -> ()
takesNoArgFunc(noArg) /* the types matches, so this is allowed */
takesNoArgFunc(oneArg) /* the types do no match here, and should not be allowed */
/* Even if it did accept the function, the type signature is not expecting `T`, so what should we expect the function to do with `T`? */