I am working on this problem and got stumped hard. The problem is posted on the picture below:
https://i.stack.imgur.com/SeXpF.png
Before it is marked as duplicate, someone has already answered this question but they changed the function definition to make their answer work. I've posted their solution here:
I'm looking for an answer that would actually work with the function definition described in the question itself.
foldListTree :: (a -> a -> a) -> a -> ListTree a -> a
I've attempted to do the solution as follows:
data ListTree a = ListLEAF [a] | ListNODE [(ListTree a)]
deriving (Show, Read, Eq)
foldListTree :: (a -> a -> a) -> a -> ListTree a -> a
foldListTree f base (ListLEAF a) = foldr f base a
foldListTree f base (ListNODE iL) = foldListTree f base (map f iL)
However I get an error:
Couldn't match expected type `ListTree a' with actual type `[a -> a]'
Any help would be appreciated, thanks!