Still learning haskell, and I cannot really see the difference between
data Tree a = Leaf a | Branch [Tree a]
and
data Tree a = Leaf a | Branch (Tree a) (Tree a)
What is best according to you? What is the implication of these two ways of writing ?
Node is a recursive constructor. It has a value of type a that it receives as a parameter on construction. The second parameter to Node is of type Seq a which is the type of Node itself, thus it becomes a recursive data structure.
From HaskellWiki. The Zipper is an idiom that uses the idea of “context” to the means of manipulating locations in a data structure. Zipper monad is a monad which implements the zipper for binary trees.
The branch of the first one holds a list of Trees, so potentially any number of subtrees. The 2nd is explicitly two subtrees, thus a binary tree.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With