Skip to content

Instantly share code, notes, and snippets.

@wouter-swierstra
Last active August 29, 2015 14:07
Show Gist options
  • Save wouter-swierstra/545d7142e7894f378d67 to your computer and use it in GitHub Desktop.
Save wouter-swierstra/545d7142e7894f378d67 to your computer and use it in GitHub Desktop.
// Two structs
struct One{ }
struct Two{ }
// Overloading the foo function -
// it should always take two arguments, one of type One; the other of type Two
func foo(x:One,y:Two) {return }
func foo(x:Two,y:One) {return }
// In this example, Swift's type checker figures out that x must have type Two
let bar = {x in
foo(One(),x)
}
// In this example, we construct a closure with two arguments. Now Swift's type
// checker can no longer figure out what the type of x and y must be.
// This seems strange...
let baz = {x,y in
foo(Two(),x)
foo(Two(),y)
}
Copy link

ghost commented Nov 1, 2014

To make the case even more concise: It's not even about the structs or using the variable twice in the closure:

func foo(x:String,y:Int) { return }
let bar = {x in
      foo("string",x)
}
let baz = {x in
      foo("string",x)
      let y = 23
}

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