I am trying to implement functor fmap over Data.Map.Map, but I am getting an error. I am sure that I do not need to convert the map to and from the list for this to work, but this is the best I have come up with so far.
class Functor' f where fmap' :: (a -> b) -> fa -> fb instance Functor' (Map.Map k) where fmap' fm | Map.null m = Map.empty | otherwise = let x:xs = Map.toList m mtail = Map.fromList xs a = fst x b = snd x in Map.insert a (fb) (fmap f mtail)
Error:
No instance for (Ord k) arising from a use of `Map.fromList' In the expression: Map.fromList xs In an equation for `mtail': mtail = Map.fromList xs In the expression: let x : xs = Map.toList m mtail = Map.fromList xs a = fst x .... in Map.insert a (fb) (fmap f mtail)
Any ideas?
source share