Source: Hutton, Graham. "Programming in Haskell" (p. 267)
- Show how the Maybe type can be made foldable and traversable, by giving explicit definitions for fold, foldMap, foldr, foldl and traverse.
I did foldr definition. For the purposes of checking my solution, I found online this code:
-- foldr :: (a -> b -> b) -> b -> Maybe a -> b
foldr _ _ Nothing = mempty
foldr f v (Just a) = f a v
It seems the acumulator should be returned in the base case (instead of mempty). Is that right ?