Add syntax for currying lambdas

Currently currying requires writing out all braces

val func: (Int) -> (Int) -> Int = { a -> { b -> a + b } }

and it’s quite verbose. A solution is to use the extension function provided by arrow-kt

val func: (Int) -> (Int) -> Int = { (a: Int, b: Int) -> a + b }.curried()

but it involved external libraries or copying an extension function to many different projects. Also sometimes the type inference can’t figure out the parameter types.

I suggest a new syntax for currying that allows you to omit the braces

// Format
{ parameters -> [ parameters -> [...]] body }

// Example
val func: (Int) -> (Int) -> Int = { a -> b -> a + b}

This can be understoof as each arrow -> represents one layer of currying, which I think is pretty intuitive. Personally I don’t write compilers, sorry if this is hard to implement with the current architecture

3 Likes

Yeah I agree. With Kotlin’s syntax for lambdas with braces, unlike in Scala or Haskell, it’s a bit ugly to write a curried lambda.