Sometimes I myself use different types of trees in Haskell, and I donโt know what they are called, or where you can get additional information about the algorithms that use them or class instances for them, or even any previously existing hackage code or library.
Examples:
Binary trees where the labels are on leaves or branches:
data BinTree1 a = Leaf | Branch {label :: a, leftChild :: BinTree1 a, rightChild :: BinTree1 a} data BinTree2 a = Leaf {label :: a} | Branch {leftChild :: BinTree2 a, rightChild :: BinTree2 a}
Similarly, trees with labels for each child node or a common label for all their children:
data Tree1 a = Branch {label :: a, children :: [Tree1 a]} data Tree2 a = Branch {labelledChildren :: [(a, Tree2 a)]}
Sometimes I start using Tree2 , and somehow during development it will be reorganized into Tree1 , which seems easier to use, but I never thought about that. Is there any duality here?
In addition, if you can post several other types of trees that you think are useful, please.
In short: everything you can tell me about these trees will be helpful! :)
Thanks.
EDIT:
Clarification: this is not homework. It's just that I usually use these data types and create instances (Functor, Monad, etc.), and maybe, if I call them, I would find libraries with implemented materials and more theoretical information about them.
Usually, when there is a tree in the name in the Hackage library, it implements BinTree2 or some version of a non-binary tree with labels only on the sheets, so it seems to me that maybe Tree2 and BinTree2 have a different name or identifier.
I also feel that there may be some kind of duality or isomorphism, or a way to turn code that uses Tree1 into code that uses Tree2 with some conversion. Here? Maybe this is just an impression.