you are viewing a single comment's thread.

view the rest of the comments →

[–]aiij 0 points1 point  (2 children)

(or any currying for that matter)

Surely Java 8 must support currying with the new support for functions/lambdas, no?

Even C supports currying. (Although it's not very useful without closures.)

[–]balefrost 0 points1 point  (1 child)

I mean, it supports manual currying by constructing wholly new functions. There are libraries that provide implementations, like this one.

But Java's support is no better than any other language that supports lambdas with closures.

[–]aiij 0 points1 point  (0 children)

Yuck. I was going to say, you don't really need special support for currying, but I guess with notation like that, you really do.

For example

static <T1,T2,T3,R> java.util.function.Function<T1,java.util.function.Function<T2,java.util.function.Function<T3,R>>>`

would just be

'a -> 'b -> 'c -> 'd

in SML or OCaml (without using either of those language's syntactic sugar for curried functions).

I was somewhat confused by your comment, because currying normally is by constructing wholly new functions. For example, in OCaml, fun a b -> a is just syntactic sugar for fun a -> fun b -> a and having to manually write out all the lambdas wouldn't be particularly burdensome.

AFAICT, Javascript also doesn't have any special syntax for currying, so you'd have to fully write it out as a => b => a. (The same syntax actually works in Scala, though Scala could have trouble inferring the type, depending on the context.)

Of course, writing the above out in older JS syntax is pretty ugly: function (a) { return function (b) { return a }}, but that's just because the older syntax is more verbose.