Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

Incorrect tree node definition in pages/Advanced Types.md #1339

Open
juanigaray opened this issue Jul 31, 2020 · 0 comments
Open

Incorrect tree node definition in pages/Advanced Types.md #1339

juanigaray opened this issue Jul 31, 2020 · 0 comments

Comments

@juanigaray
Copy link

This is minor but I'm reporting it to make my PR reference an issue.

The Tree type defines a node of a tree which must have two Tree chidren. This makes it impossible for there to be leaf nodes.

type Tree<T> = {
    value: T;
    left: Tree<T>;
    right: Tree<T>;
}

If a tree must have a child and that child can't be anything other than a tree, then that causes every child to need a child of its own. A leaf node doesn't have any children and you can't have an infinite tree, so this type wouldn't work in real code.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant