In Roc, function with two arguments have type a, b -> c
. Other functional language usually have a -> b -> c
syntax to represent curried function. Is there a specific reason why Roc uses the first syntax for function types?
https://www.roc-lang.org/faq#curried-functions
In short, it can be very easy to write code using currying that's harder for beginners to understand, and there's isn't enough of a benefit to overcome that detriment
You could argue that Roc does write function signatures in that curried style, but only if you manually write a curried function, so this function
f = \x -> \y -> y + x
has the type
Num a -> (Num a -> Num a)
The real difference is that Roc doesn't automatically curry functions
And Roc doesn't automatically curry functions for the reasons that Sam explained and linked to :)
Honestly I must say that currying is one of the FP features I wish I had in every language. In Roc it is not that difficult to write curried functions because the calling syntax doesn't change I assume, but in languages like C# (and other C style languages) you have to type multiple parens pairs for the required argument lists, for example MyCurriedMethod(a)(b)(c)
(looks awful and most people I know even don't know what it means because it seems to by something different than a normal method call) instead of MyCurriedMethod(a, b, c)
. Most of the time currying isn't needed, but at times I find it very handy and useful.
@Akeshihiro for us to call a curried function, we couldn't just call foo a b
, either foo
takes two arguments sans currying or there's a type error. With currying, it'd be either (foo a) b
or foo a |> b
So it may not look as clean as you'd like in Roc
Sam Mohr said:
Akeshihiro for us to call a curried function, we couldn't just call
foo a b
, eitherfoo
takes two arguments sans currying or there's a type error. With currying, it'd be either(foo a) b
orfoo a |> b
Well, then my assumption was wrong, thank you. But even then it is way better than in C style languages :D
I don't think foo a |> b
is right..... b |> (foo a)
maybe? Though I'm not sure if roc respects the parens there
Last updated: Jul 06 2025 at 12:14 UTC