What would be a good solution to Tree : (Post, List Tree)
Since the roc compiler states:
── CYCLIC ALIAS in main.roc ────────────────────────────────────────────────────
The Tree alias is self-recursive in an invalid way:
76│ Tree : (Post, List Tree)
^^^^
Recursion in aliases is only allowed if recursion happens behind a
tagged union, at least one variant of which is not recursive.
────────────────────────────────────────────────────────────────────────────────
I think, that this type should be allowed, since List may contain 0 items. What would be a good workaround or if this is intended a better solution?
Maybe Tree : [Leaf Post, Subtree (List Tree)]
? Just on my phone so hard to check
@Adrian this should be allowed, but we don't support detecting this case yet
as a workaround, you can use an opaque type instead of a type alias
basically change the :
to :=
and then write tree = @Tree (post, list)
to create a Tree
, and @Tree (post, list) = tree
to unwrap a Tree
I have a NestSet implementation here which might help with ideas. Theres also the Graph example which might be helpful too.
Adrian has marked this topic as resolved.
Last updated: Jul 06 2025 at 12:14 UTC