I'm a bit confused about what a RocList is supposed to represent. A quick glance at the implementation seems to indicate it's a flat (heap) array. So with a List U32
can I assume that I get a single contiguous chunk of memory? Or do I get a "linked list" with pointers to individual U32s?
What if I have a List BigBooba
, do I get an array of pointers, or a linked list of Boobas or are all Boobas on the heap next to each other?
Would a RocArray guarantee memory adjacency or does RocList already come with such a guarantee ???
Sorry for all the questions, I'm new to Roc!!
I find the zig builtin implementation easier to understand https://github.com/roc-lang/roc/blob/main/crates/compiler/builtins/bitcode/src/list.zig
Single contiguous chnk of memory I think is the answer.
Luke Boswell said:
I find the zig builtin implementation easier to understand https://github.com/roc-lang/roc/blob/main/crates/compiler/builtins/bitcode/src/list.zig
I also came across this https://github.com/roc-lang/roc/blob/main/crates/roc_std/src/roc_list.rs
Are these equivalent?
Presumably I guess. I'm not really familiar with this, but the compiler is in Rust using that crate, and the builtins are in Zig using the zig module. And the talk to each other no issue.
They should be equivalent, but the rust version is more likely to be buggy, out or date, or wrong in places. I also, think the zig version is a lot more direct and easy to understand
Anyway, yeah our RocList
is really like a C++ vector or Java ArrayList.
Shaiden Spreitzer has marked this topic as resolved.
Last updated: Jul 06 2025 at 12:14 UTC