I'm trying to implement a kind of zip-function for trees. For this example each tree-node has an Integer Value (Label), a transformative function (Label->Label) and a List of sub-trees [Tree].
the tzp (tree-zip) Method takes two trees and adds their values together based on some criteria. Here's the question:
How do I get my function to recursively take the next subtree of each [Tree]-List?
My current implementation in case you're curious
tzp :: (Label -> Label -> Label) -> Tree -> Tree -> Tree
tzp arithmeticF t1 t2 = if ((getNodeValue t1) == (getNodeValue t2)) then (Node (arithmeticF (getNodeValue t1)) ((getNodeFunction t1) . (getNodeFunction t2) (getNodeValue t1)) (map (tzp arithmeticF) (getSubTrees t1) (getSubTrees t2)))
the culprit is this part:
(map (tzp arithmeticF) (getSubTrees t1) (getSubTrees t2))
since map can't work with two
lists. To be precise I have to apply the function to the n'th element of either list. So first with first, second with second, etc.
Any help is greatly appreciated!
zipWith
? – bheklilr