module MonMap where import qualified Data.Map.Strict as Map newtype MonMap k v = MonMap (Map.Map k v) deriving (Show) instance Functor (MonMap k) where fmap f (MonMap m) = MonMap (fmap f m) instance (Ord k, Semigroup v) => Semigroup (MonMap k v) where MonMap m1 <> MonMap m2 = MonMap (Map.unionWith (<>) m1 m2) instance (Ord k, Monoid v) => Monoid (MonMap k v) where mempty = MonMap mempty singleton :: k -> v -> MonMap k v singleton = (MonMap .) . Map.singleton lookup :: Ord k => k -> MonMap k v -> Maybe v lookup k (MonMap m) = Map.lookup k m