Why can't () as an argument list be regarded as the same as (()) just like no return type is regarded as the same as `-> ()`?<br><div class="gmail_quote"><div dir="ltr">On Sun, Jul 3, 2016 at 17:41 Austin Zheng via swift-evolution <<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Void is just a typealias for (). () is the only type in Swift whose type and only instance are spelled the same way, as far as I can tell. This isn't true for Void, since Void is only a type, not the value.<br>
<br>
As for the zero-argument/one-argument problem...how often does realistic code need to pass in a zero-argument function to a function type that takes one argument? If the answer is "often", we should consider what it would take to define an implicit conversion. Otherwise, maybe we can get away with a standard library adapter that can be used to wrap a () -> T as a U -> T (where U = () or something).<br>
<br>
Austin<br>
<br>
<br>
> On Jul 3, 2016, at 3:35 PM, Vladimir.S via swift-evolution <<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>> wrote:<br>
><br>
> On 04.07.2016 0:47, Anton Zhilin via swift-evolution wrote:<br>
>> Vladimir.S via swift-evolution <swift-evolution@...> writes:<br>
>><br>
>>> On 03.07.2016 23:53, Anton Zhilin via swift-evolution wrote:<br>
>>>> let x = (Int, Int)(1, 2) //=> (1, 2)<br>
>>>> let y = (Int)(1) //=> 1<br>
>>>> let z = ()() // error :(<br>
>>>><br>
>>>> Am I requesting too much from type checker?<br>
>>><br>
>>> As I understand, because () is Void, you can't have anything additional<br>
>> for<br>
>>> it. It is just Void, like you write 'let z = Void Void'. I.e. only 'let<br>
>> z =<br>
>>> ()' allowed.<br>
>><br>
>> In the example, that's how I expect that to parse:<br>
>><br>
>> let z = ().init() // just demo, does not compile<br>
>><br>
>> I mean, first () is type, and second () is its initializer.<br>
>><br>
>> By the way, this is one thing that Void can do, but () cannot.<br>
>> Are there any others?<br>
>><br>
><br>
> I believe in this case () is playing a role of instance of type Void, i.e. empty tuple. I don't think you can expect ().init()<br>
><br>
> Also:<br>
> func f(_ x: ())->() {}<br>
> f(())<br>
> //f(Void) // argument passed to call that takes no arguments<br>
><br>
> And just some fun:<br>
><br>
> let x1 : Void<br>
> //let x2 : Void = Void // cannot convert value of type 'Void.Type' (aka '().Type') to specified type 'Void' (aka '()')<br>
> let x3 : ()<br>
> let x4 : () = ()<br>
> let x5 : Void = ()<br>
> //let x4 : () = Void // cannot convert value of type 'Void.Type' (aka '().Type') to specified type '()'<br>
><br>
> print(().dynamicType) // ()<br>
> print(().self) // ()<br>
> // print("Void.dynamicType = ", Void.dynamicType) // '.dynamicType' is not allowed after a type name<br>
> print(Void.self) // ()<br>
> print(().dynamicType == Void.self) // true<br>
><br>
><br>
>> _______________________________________________<br>
>> swift-evolution mailing list<br>
>> <a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br>
>> <a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
>><br>
> _______________________________________________<br>
> swift-evolution mailing list<br>
> <a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br>
> <a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
<br>
_______________________________________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
</blockquote></div>