[Question] Types of functions


(Anton Zhilin) #1

// Swift 2.2print([Int].append.dynamicType) //=> inout Array<Int> ->
Int -> ()print(print.dynamicType) //=> (Array<protocol<>>, String,
String) -> ()
// Swift 3print(type(of: [Int].append)) //=> (inout Array<Int>) ->
(Int) -> ()print(type(of: print)) //=> ((Array<Any>, String, String))
-> ()

Question #1: Methods are still curried. If I’m not mistaken, there was an
accepted proposal that uncurries methods. Is it going to be implemented for
Swift 4 Stage 1?

Question #2: Why nested tuple in type of print? Is it just a formatter bug,
or… do functions still take tuples under the hood? If so, then perhaps,
implementation needs to be modified to actually use new model, and not just
make it look like it does.


(Adrian Zubarev) #2

We should move this thread to swift-users.

Here is something that I just tried:

func foo(_: Int, _: Int) {}
func boo(_: (Int, Int)) {}
type(of: foo) == type(of: boo) //=> true ; (((Int, Int)) -> ()).Type

let tuple = (0, 42)
foo(tuple) // Tuple splat was removed => Error
boo(tuple) // Expected => Okay

···

--
Adrian Zubarev
Sent with Airmail

Am 5. Oktober 2016 um 17:02:43, Anton Zhilin via swift-evolution (swift-evolution@swift.org) schrieb:

print(type(of: [Int].append)) //=> (inout Array<Int>) -> (Int) -> ()
print(type(of: print)) //=> ((Array<Any>, String, String)) -> ()


(Vladimir) #3

(Adrian, are you from the future? :wink:

We should move this thread to swift-users.

Here is something that I just tried:

>func foo(_: Int, _: Int) {} func boo(_: (Int, Int)) {} type(of: foo) ==
type(of: boo) //=> true ; (((Int, Int)) -> ()).Type let tuple = (0, 42)
foo(tuple) // Tuple splat was removed => Error boo(tuple) // Expected => Okay |

IIUC, as soon as SE-0110(https://github.com/apple/swift-evolution/blob/master/proposals/0110-distingish-single-tuple-arg.md) was not marked as "implemented" yet according to https://apple.github.io/swift-evolution/, we still have some rudiments of older design.

I expect that implementation of SE-0110 will separate types
(Int, Int) -> ()
and
((Int, Int)) -> ()

Also implementation of SE-0110 should remove implicit Void parameter in function defined with no parameters

func f() {}
func g() {}
f(g()) // now works, will be error

func foo(f: () -> ()) { f() }
foo {x in print(x)} // now works, will be error

I'd really like to know when this proposal will be implemented : in Swift 3.x or in 4.x

···

On 12.11.2016 11:38, Adrian Zubarev via swift-users wrote:

--
Adrian Zubarev
Sent with Airmail

Am 5. Oktober 2016 um 17:02:43, Anton Zhilin via swift-evolution
(swift-evolution@swift.org <mailto:swift-evolution@swift.org>) schrieb:

print(type(of: [Int].append)) //=> (inout Array<Int>) -> (Int) -> ()
print(type(of: print)) //=> ((Array<Any>, String, String)) -> ()

_______________________________________________
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


(Adrian Zubarev) #4

Maybe :smiley: No actually I had to test an iOS app feature depending on that date but forget to reset the system date and time.

···

--
Adrian Zubarev
Sent with Airmail

Am 6. Oktober 2016 um 20:38:53, Vladimir.S (svabox@gmail.com) schrieb:

(Adrian, are you from the future? :wink: