Anonymous Function Shorthand: how to refer the same argtument twice


Irwin
 

Hi,

I have this example:

val double-me = fn (x: Int) -> Int : (x * x)
println(double-me(4))

how can i achieve the same by using the shorthand for this kind of function? this doesn't work because the function is expecting 2 arguments but i really want to refer the same arg twice:

val double-me = {_ * _}
println(double-me(2))

tnks!


 

If you are using the latest experimental version (the stable version is really old, and we need to update it), then this syntax will work:

val double-me = {_0 * _0}
println(double-me(2))

Best, Patrick