I implemented a function that searched for a specific node inside a tree. Here's the function and it works:
searchTree :: String -> Tree String -> Bool
searchTree value tree =
foldl (\acc x -> if value `elem` x then True else acc) False (levels tree)
Then, I'm trying to implement the same function, but this time, I want to add a Writer Monad. This one doesn't work and the compiler says "Couldn't match expected type 'Writer [String] Bool' with actual type 'Bool' " -> The error is in the 4th line, in the instruction 'return True'.
searchTree :: String -> Tree String -> Writer [String] Bool
searchTree value tree =
foldl (\acc x -> if value `elem` x then do
tell ["My logger message "]
return True else acc) return False (levels tree)
Thanks in advance.