Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do curried functions require external parameter names?

Tags:

swift

currying

Given this simple currying function:

func foo(x:Int)(y:Int)->String{
  return "\(x) with \(y)"
}

I'd expect to be able to do something like this:

let bar = foo(1)
bar(2) //<- error: Missing argument label 'y:' in call

If I label the call to bar (as in bar(y:2)) everything works fine. But I don't understand why the parameter name is necessary. Is there any way to avoid it?

The obvious thing:

func foo(x:Int)(_ y:Int)->String ...

does not seem to work.

like image 930
jemmons Avatar asked Jun 11 '14 19:06

jemmons


1 Answers

It's a bug, you should file a radar at bugreport.apple.com

As a confirmation, if you place an underscore, like this

func foo(x: Int)(_ y: Int) -> String

you get a warning

Extraneous '_' in parameter: 'y' has no keyword argument name

So it explicitly says that y has no external name, but it still requires one when called, which is clearly against the language specification.

like image 92
Gabriele Petronella Avatar answered Oct 03 '22 22:10

Gabriele Petronella