I am trying to define a function which will return the list of all paths through a given binary tree. I have the following functions defined already:
data BTree a = Leaf a | Node a (BTree a) (BTree a)
deriving (Show,Eq)
paths :: BTree a -> [[a]]
paths (Leaf a) = [[]]
paths (Node x left right) = map (x:) (paths left ++ paths right)
With this function I have the following results for example:
[[5,4],[5,4],[5,3],[5,3]] . But I was supposed to have as a result the output [[5,4,1],[5,4,2],[5,3,3],[5,3,4]].
Do anyone know why i dont get the 3rd value?
Thank you