Skip to content

Instantly share code, notes, and snippets.

@bjhomer
Last active August 29, 2015 14:18
Show Gist options
  • Save bjhomer/9de56809641c3d8aeedb to your computer and use it in GitHub Desktop.
Save bjhomer/9de56809641c3d8aeedb to your computer and use it in GitHub Desktop.
Disambiguating methods with external parameter names
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 ';'
@pitiphong-p
Copy link

IIRC Xcode 6.3 beta has mentioned something about curried function with external parameter name. Have you tried this on 6.3 yet?

@pitiphong-p
Copy link

Looks like this doesn't work on 6.3 beta too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment