enum Tree<T> {
case Leaf(T)
indirect case Node(Tree, Tree)
}
But with structs, last time I checked, you can not do
struct LinkedList<T> {
var value : T
indirect var tail : LinkedList<T>?
}
This may be tolerable for internal types, but what if you interface with a REST API from another company and some API call can return a type where the json schema is recursive? Do I just have to switch to reference types?
Maybe allowing to annotate optional struct members as indirect would be a cleaner solution in the future.
The naive implementation of this would have to allocate for every new value, FWIW. Presumably you’re imagining Optional<Box<LinkedList>>, but it would actually be Box<Optional<LinkedList>> unless we made an exception for optionals.