summaryrefslogtreecommitdiff
path: root/MonMap.hs
diff options
context:
space:
mode:
Diffstat (limited to 'MonMap.hs')
-rw-r--r--MonMap.hs22
1 files changed, 22 insertions, 0 deletions
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