Stream: beginners

Topic: function


view this post on Zulip Audrey Gao (Mar 31 2023 at 05:49):

Are functions always have a return value? Or is there any keyword equivalent to "void"? I also wondered how Roc handles mutually recursive definitions of functions.

view this post on Zulip itmuckel (Mar 31 2023 at 06:34):

There is {}, maybe that works? I think it's an empty record, but you can use it as a type as well

view this post on Zulip Nick Hallstrom (Mar 31 2023 at 07:53):

{} is the closest to void, but a function that returns it can't actually do anything in a purely functional language like Roc. What is the function you're trying to define? You probably need it to return something like Task {} [] instead, since that can actually do a side effect.

view this post on Zulip Ayaz Hafiz (Mar 31 2023 at 14:11):

Mutually recursive functions work in the standard way; you must write all functions involved in a mutual recursion next to each other, but otherwise there are no syntactic restrictions. Only functions can be recursive (respectively, mutually recursive), ground values cannot be recursive. Roc does not support polymorphic recursion.

view this post on Zulip Audrey Gao (Mar 31 2023 at 22:46):

Thanks so much for the explanation!


Last updated: Jul 05 2025 at 12:14 UTC