From 5d1d3b4f251bf938648d7d21c6641a1a0cc0768b Mon Sep 17 00:00:00 2001 From: Tom Smeding Date: Sat, 26 Dec 2020 18:08:15 +0100 Subject: Initial --- MonMap.hs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 MonMap.hs (limited to 'MonMap.hs') diff --git a/MonMap.hs b/MonMap.hs new file mode 100644 index 0000000..dd70ec3 --- /dev/null +++ b/MonMap.hs @@ -0,0 +1,22 @@ +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 -- cgit v1.2.3-70-g09d2