From 9edec84c77e0c008f61c493ae566d36fb4e37798 Mon Sep 17 00:00:00 2001 From: Georgios Karachalias Date: Fri, 3 Jul 2020 18:03:54 +0200 Subject: [PATCH] Add missing Functor/Foldable/Traversable instances for SymbolMap --- asterius/src/Asterius/Types/SymbolMap.hs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/asterius/src/Asterius/Types/SymbolMap.hs b/asterius/src/Asterius/Types/SymbolMap.hs index 06c66afb82..42af55e2f9 100644 --- a/asterius/src/Asterius/Types/SymbolMap.hs +++ b/asterius/src/Asterius/Types/SymbolMap.hs @@ -200,6 +200,16 @@ mapKeys fn = fromListSM . (map (\(k, e) -> (fn k, e))) . toListSM -- ---------------------------------------------------------------------------- +instance Functor SymbolMap where + fmap f (SymbolMap m) = SymbolMap $ IM.map (\(k, e) -> (k, f e)) m + +instance Foldable SymbolMap where + foldr f z (SymbolMap m) = IM.foldr (\(_, e) b -> f e b) z m + +instance Traversable SymbolMap where + traverse f (SymbolMap m) = + SymbolMap <$> traverse (\(k, x) -> fmap (\e -> (k, e)) (f x)) m + -- | /O(n*log n)/. Build a symbol map from a list of key/value pairs. {-# INLINE fromListSM #-} fromListSM :: [(EntitySymbol, a)] -> SymbolMap a