Stream: beginners

Topic: I have a question about function types


view this post on Zulip Cheezone (Jun 30 2024 at 06:10):

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?

view this post on Zulip Sam Mohr (Jun 30 2024 at 06:12):

https://www.roc-lang.org/faq#curried-functions

view this post on Zulip Sam Mohr (Jun 30 2024 at 06:13):

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

view this post on Zulip Hannes (Jun 30 2024 at 10:23):

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

view this post on Zulip Hannes (Jun 30 2024 at 10:24):

And Roc doesn't automatically curry functions for the reasons that Sam explained and linked to :)

view this post on Zulip Akeshihiro (Jun 30 2024 at 12:26):

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.

view this post on Zulip Sam Mohr (Jun 30 2024 at 12:35):

@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

view this post on Zulip Sam Mohr (Jun 30 2024 at 12:35):

So it may not look as clean as you'd like in Roc

view this post on Zulip Akeshihiro (Jun 30 2024 at 13:03):

Sam Mohr said:

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

Well, then my assumption was wrong, thank you. But even then it is way better than in C style languages :D

view this post on Zulip Brendan Hansknecht (Jun 30 2024 at 16:57):

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