Stream: beginners

Topic: doubly linked lists


view this post on Zulip dank (Mar 26 2023 at 08:03):

as I understand, it is currently impossible to represent a doubly linked list in roc due to it requiring ref cycles which roc disallows
would it always be the case or at some point will roc try to integrate a cycle detector?
im totally fine with _absolutely not_, because it does add complexity and a performance penalty which idk if needed, as i've never seen a use for something _like_ doubly linked lists outside of homework
just wondering about goals here

view this post on Zulip Ron Panduwana (Mar 26 2023 at 08:37):

we can use opaque types to prevent things (such as list nodes) to be promiscuously referenced,
combine this with weak ref and we can have cyclic ref without needing cycle detector

view this post on Zulip Ron Panduwana (Mar 26 2023 at 08:38):

which can be useful for lots of data types, even if deque is considered good-for-nothing

view this post on Zulip Ron Panduwana (Mar 26 2023 at 08:42):

this of course needs the "hey we can do in-place mutation here"-detector working to be useful, otherwise it's moot point

view this post on Zulip dank (Mar 26 2023 at 08:46):

interesting

view this post on Zulip Brendan Hansknecht (Mar 26 2023 at 14:49):

I'm pretty sure cycles of this nature are explicitly not allowed in the language with no plans of being added

view this post on Zulip Brendan Hansknecht (Mar 26 2023 at 14:56):

The only ways to get a doubly linked list in roc would be up either

  1. Use integer indices as pointers to get around this limitation in roc (means essentially doing everything manually)
  2. Use the host to give you the type and manage it for you

view this post on Zulip Richard Feldman (Mar 26 2023 at 17:37):

dank said:

at some point will roc try to integrate a cycle detector?

the current plan is never to do this - I think if there was a lot of demand for a specific data structure (e.g. a doubly linked list), the discussion would be whether we can (and if so whether we should) add a builtin to address the use case

view this post on Zulip Richard Feldman (Mar 26 2023 at 17:37):

another possibility is being able to optimize our way into it, but that seems less likely to work out in practice :big_smile:


Last updated: Jul 05 2025 at 12:14 UTC