Stream: beginners

Topic: A couple of remaining questions


view this post on Zulip Yunti (Dec 30 2024 at 13:28):

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

view this post on Zulip Anton (Dec 30 2024 at 13:41):

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)"

view this post on Zulip Anton (Dec 30 2024 at 13:45):

For ?: https://www.roc-lang.org/tutorial#the-postfix-try-operator

view this post on Zulip Anton (Dec 30 2024 at 13:47):

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.

view this post on Zulip Anton (Dec 30 2024 at 13:49):

Something similar to type classes: https://www.roc-lang.org/abilities (may change in the future)

view this post on Zulip Anton (Dec 30 2024 at 13:51):

Do you use different operators for + eg like ocaml?

In Roc + is used for integer addition, float addition and dec addition

view this post on Zulip Richard Feldman (Dec 30 2024 at 14:04):

Abilities actually qualify as ad hoc polymorphism

view this post on Zulip Richard Feldman (Dec 30 2024 at 14:04):

but, importantly, they are not higher-kinded - which is a difference between them and Haskell's typeclasses

view this post on Zulip Richard Feldman (Dec 30 2024 at 14:05):

we can support operator overloading, but currently don't. Probably will after static dispatch lands though. :big_smile:

view this post on Zulip Yunti (Dec 30 2024 at 16:25):

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.

view this post on Zulip Norbert Hajagos (Dec 30 2024 at 16:32):

#ideas > ✔ lambda syntax
and also
#ideas > Remove the need for backslashes for lambdas?
are some discussions around that.

view this post on Zulip Yunti (Dec 30 2024 at 16:46):

Thanks

view this post on Zulip Yunti (Dec 30 2024 at 17:13):

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) ?

view this post on Zulip Anton (Dec 30 2024 at 17:23):

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

view this post on Zulip Richard Feldman (Dec 30 2024 at 17:28):

I don't think anyone has started on static dispatch yet

view this post on Zulip Richard Feldman (Dec 30 2024 at 17:29):

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:

view this post on Zulip Yunti (Dec 30 2024 at 18:15):

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