Im gradually getting up to speed with Roc, but i a couple of things I’m not sure of
what does the | thing mean I’ve seen in some code snippets? Is it a new syntax?
What does the trailing ? mean (eg as mentioned in the static dispatch proposal?
Does roc currently have any ad hoc polymorphism, operator overloading , (type classes or similar)?
Do you use different operators for + eg like ocaml?
thx
The |
is the new lambda syntax:
new syntax:
credits = List.map songs |song|
"Performed by $(song.artist)"
old syntax:
credits = List.map songs \song ->
"Performed by $(song.artist)"
For ?
: https://www.roc-lang.org/tutorial#the-postfix-try-operator
Roc does not have ad hoc polymorphism or operator overloading. Operator overloading has been discussed a lot but I don't think we have a confirmed proposal on it yet.
Something similar to type classes: https://www.roc-lang.org/abilities (may change in the future)
Do you use different operators for + eg like ocaml?
In Roc +
is used for integer addition, float addition and dec addition
Abilities actually qualify as ad hoc polymorphism
but, importantly, they are not higher-kinded - which is a difference between them and Haskell's typeclasses
we can support operator overloading, but currently don't. Probably will after static dispatch lands though. :big_smile:
Nice thanks for replying that’s really helpful. Is there a paper / discussion on the lambda syntax? I may have missed that when looking around.
#ideas > ✔ lambda syntax
and also
#ideas > Remove the need for backslashes for lambdas?
are some discussions around that.
Thanks
I’m keen to start having a go of coding in Roc over the holidays (whilst there is a bit of time) but there seems to be a lot in flux at the moment. Is there a branch with purity inference, static dispatch, for and var in it to play around with or some of these (these seem like the biggest current changes in terms of coding style) ?
Purity inference is already available on nightly: examples
Not sure if static dispatch is already in progress, work on for and var has not started yet I think
I don't think anyone has started on static dispatch yet
that's an interesting one in that it exclusively does things we already do (e.g. type inference, looking up implementations in different modules - which is what Abilities already do) but it doesn't do them quite the same way as anything that's in the compiler today :big_smile:
Ok thanks , maybe I’ll have a go with the nightly on a few examples and sketch out what the code would look like if those other features were in to get a feel for the language.
Last updated: Jul 06 2025 at 12:14 UTC