Last active
August 29, 2015 14:18
-
-
Save bjhomer/9de56809641c3d8aeedb to your computer and use it in GitHub Desktop.
Disambiguating methods with external parameter names
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Cocoa | |
func curry<A, B, C> ( f: (A, B) -> C ) -> (A -> B -> C) { | |
return { x in | |
return { y in | |
return f(x, y) | |
} | |
} | |
} | |
func add(a: Int, b: Int) -> Int { | |
return a + b | |
} | |
class Foo { | |
func add(a: Int, b: Int) -> Int { | |
return a + b | |
} | |
func myAdd(a: Int, b: Int) -> Int { | |
return a + b | |
} | |
func myAdd(a: Int, doubling b: Int) -> Int { | |
return a + 2*b | |
} | |
} | |
let foo = Foo() | |
let add2 = curry(add)(2) | |
add2(5) // 7 | |
let boundAdd2 = curry(foo.add)(2) | |
boundAdd2(4) // 6 | |
let myAdd2 = curry(foo.myAdd)(2) // Error: ambiguous use of 'myAdd' | |
let myDoubledAdd2(foo.myAdd(doubling:))(2) // Error: consecutive statements on a line must be separated by ';' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Looks like this doesn't work on 6.3 beta too.