Stream: beginners

Topic: Idiomatic roc, \arg vs |arg|


view this post on Zulip Ben (Feb 12 2025 at 12:23):

I'm really new to roc and enjoying it so far. Some of the examples I've seen define arguments in a couple ways, and I can't see from documentation the difference.

As I understand these two are the same?

isSeven : I64 -> Bool
isSeven = \n ->
    n == 7
isSeven : I64 -> Bool
isSeven = |n|
    n == 7

Is there something subtly different about the two? Is one considered more "idiomatic" (the second seems to be in roc docs)?

view this post on Zulip Jesse Nutt (Feb 12 2025 at 13:51):

There has recently been a lot of changes to the syntax. Both of these notations are identical in what they do, because they ARE effectively the same thing (lambdas)

the \x -> notation is to be replaced with the |x| syntax going forward, but the docs are out of sync with the actual state of the language

view this post on Zulip Ben (Feb 12 2025 at 13:55):

Ah thanks, that makes sense! So if I've understood 1 is old, 2 is new, and at some point 2 will probably be the only way to do it?

view this post on Zulip Jesse Nutt (Feb 12 2025 at 14:26):

Yes, that is correct

view this post on Zulip Hannes (Feb 13 2025 at 09:43):

If you run roc format --migrate ... the compiler will automatically upgrade your syntax to the latest version :)


Last updated: Jul 06 2025 at 12:14 UTC