So I'm learning Haskell and I have to implement a treeunzip function that takes a tree of the type (Tree (a,b)) where 'a' and 'b' are integers and returns a list of the two trees unzipped, that is (Tree a, Tree b).
I can get one of the two trees but I can't put them together in a list. What I came up with is this:
treeunzip :: (NewTree) -> (treeunzipL, treeunzipR)
NewTree is defined as:
data NewTree = NewLeaf | NewNode Int Int NewTree NewTree deriving Show
Tree is defined as:
data Tree = Leaf | Node Int Tree Tree deriving Show
Here are the treeunzipL and treeunzipR functions, I don't know if it matters.
treeunzipL :: (NewTree) -> (Tree)
treeunzipL NewLeaf = (Leaf)
treeunzipL (NewNode x y lSubTree rSubTree) = (Node x (treeunzipL (lSubTree)) (treeunzipL (rSubTree)))
treeunzipR :: (NewTree) -> (Tree)
treeunzipR NewLeaf = (Leaf)
treeunzipR (NewNode x y lSubTree rSubTree) = (Node y (treeunzipR (lSubTree)) (treeunzipR (rSubTree)))
Now that obviously gives me an error when loading the module because treeunzip has a signature but not an implementation. Is there any way to get around this?
Thank you.