I tried running the below code:
val f: (a: Int) => (b: Int) => (c: Int) = a + b + c
found in this thread in the REPL and IntellijIDEA but it's apparently invalid.
From the REPL:
scala> val f: (a: Int) => (b: Int) => (c: Int) = a + b + c
<console>:1: error: ')' expected but ':' found.
val f: (a: Int) => (b: Int) => (c: Int) = a + b + c
^
Anyone knows why? My scala version is 2.10.1
Thank you
You write the type as if you were writing:
val a: 5 = 5
What you want is more like
val f = (a: Int) => (b: Int) => (c: Int) => a+b+c
To elaborate further the REPL will write
f: Int => (Int => (Int => Int)) = <function1>
Because function definition is right associative you could the type of f explicitly as follows
f: Int => Int => Int => Int = (a: Int) => (b: Int) => (c: Int) => a+b+c
If you explicitly give the function type like this the compiler does not need information about what a,b, and c are and you could simply write a => b => c => a+b+c instead.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With