4 ms·
I'm defining "recursive" data structure in basically the same way everyone else does. Here's an example in Haskell: data [a] = [] | a : [a] The element i
by tombert 7y ago
I'm defining "recursive" data structure in basically the same way everyone else does. Here's an example in Haskell:
data [a] = [] | a : [a]
The element is either empty, or an element and a pointer to another list. This is recursively defined since it points to the source data structure as part of its definition.
I know that traversing a tree can be done with a stack/list; I mentioned that in my response, but the code will typically be bigger and less intuitive; if the data structure is recursive (based on my definition from above), it lends itself to a recursive algorithm.
Sure, under the hood immutable data might be dressing for something at runtime, but the compiler still needs help to use those features; if I want to loop over something and prepend to a list immutably, at least from a code perspective (not the runtime context), I need recursion to properly respect that.