Alex Rivera | Logout

Trees in Haskell

Asked 2010-12-13T17:50:27.933
21

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 ?

Edit
Report

1 Answer

57

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.

answered 2010-12-13T17:51:59.203

Your Answer