git.iko.soy/monoidal-containers
on master help sign in
Make fromList safe by requiring Semigroup on values

Rename old behavior to fromDistinctList.

commit49a081cf3f8883fa6fc00e35ae132037cece7bf3 authorElliot Cameron <eacameron@gmail.com> dateTue 2 Oct 2018, 22:00 (8 years ago) parentbe91bc5
2 files changed+18−8
src/Data/Map/Monoidal.hs+9−4 src/Data/Map/Monoidal/Strict.hs+9−4
src/Data/Map/Monoidal.hs+9−4
@@ -62,6 +62,7 @@ module Data.Map.Monoidal
6262 , fromAscListWith
6363 , fromAscListWithKey
6464 , fromDistinctAscList
65+ , fromDistinctList
6566 , fromList
6667 , fromListWith
6768 , fromListWithKey
@@ -477,8 +478,8 @@ toList :: forall k a. MonoidalMap k a -> [(k, a)]
477478toList = coerce (M.toList :: M.Map k a -> [(k, a)])
478479{-# INLINE toList #-}
479480
480−fromList :: forall k a. Ord k => [(k, a)] -> MonoidalMap k a
481−fromList = coerce (M.fromList :: [(k, a)] -> M.Map k a)
481+fromList :: forall k a. (Ord k, Semigroup a) => [(k, a)] -> MonoidalMap k a
482+fromList = fromListWith (<>)
482483{-# INLINE fromList #-}
483484
484485fromListWith :: forall k a. Ord k => (a -> a -> a) -> [(k, a)] -> MonoidalMap k a
@@ -497,8 +498,8 @@ toDescList :: forall k a. MonoidalMap k a -> [(k, a)]
497498toDescList = coerce (M.toDescList :: M.Map k a -> [(k, a)])
498499{-# INLINE toDescList #-}
499500
500−fromAscList :: forall k a. Eq k => [(k, a)] -> MonoidalMap k a
501−fromAscList = coerce (M.fromAscList :: [(k, a)] -> M.Map k a)
501+fromAscList :: forall k a. (Eq k, Semigroup a) => [(k, a)] -> MonoidalMap k a
502+fromAscList = fromAscListWith (<>)
502503{-# INLINE fromAscList #-}
503504
504505fromAscListWith :: forall k a. Eq k => (a -> a -> a) -> [(k, a)] -> MonoidalMap k a
@@ -513,6 +514,10 @@ fromDistinctAscList :: forall k a. [(k, a)] -> MonoidalMap k a
513514fromDistinctAscList = coerce (M.fromDistinctAscList :: [(k, a)] -> M.Map k a)
514515{-# INLINE fromDistinctAscList #-}
515516
517+fromDistinctList :: forall k a. Ord k => [(k, a)] -> MonoidalMap k a
518+fromDistinctList = coerce (M.fromList :: [(k, a)] -> M.Map k a)
519+{-# INLINE fromDistinctList #-}
520+
516521filter :: forall k a. (a -> Bool) -> MonoidalMap k a -> MonoidalMap k a
517522filter = coerce (M.filter :: (a -> Bool) -> M.Map k a -> M.Map k a)
518523{-# INLINE filter #-}
src/Data/Map/Monoidal/Strict.hs+9−4
@@ -62,6 +62,7 @@ module Data.Map.Monoidal.Strict
6262 , fromAscListWith
6363 , fromAscListWithKey
6464 , fromDistinctAscList
65+ , fromDistinctList
6566 , fromList
6667 , fromListWith
6768 , fromListWithKey
@@ -476,8 +477,8 @@ toList :: forall k a. MonoidalMap k a -> [(k, a)]
476477toList = coerce (M.toList :: M.Map k a -> [(k, a)])
477478{-# INLINE toList #-}
478479
479−fromList :: forall k a. Ord k => [(k, a)] -> MonoidalMap k a
480−fromList = coerce (M.fromList :: [(k, a)] -> M.Map k a)
480+fromList :: forall k a. (Ord k, Semigroup a) => [(k, a)] -> MonoidalMap k a
481+fromList = fromListWith (<>)
481482{-# INLINE fromList #-}
482483
483484fromListWith :: forall k a. Ord k => (a -> a -> a) -> [(k, a)] -> MonoidalMap k a
@@ -496,8 +497,8 @@ toDescList :: forall k a. MonoidalMap k a -> [(k, a)]
496497toDescList = coerce (M.toDescList :: M.Map k a -> [(k, a)])
497498{-# INLINE toDescList #-}
498499
499−fromAscList :: forall k a. Eq k => [(k, a)] -> MonoidalMap k a
500−fromAscList = coerce (M.fromAscList :: [(k, a)] -> M.Map k a)
500+fromAscList :: forall k a. (Eq k, Semigroup a) => [(k, a)] -> MonoidalMap k a
501+fromAscList = fromAscListWith (<>)
501502{-# INLINE fromAscList #-}
502503
503504fromAscListWith :: forall k a. Eq k => (a -> a -> a) -> [(k, a)] -> MonoidalMap k a
@@ -512,6 +513,10 @@ fromDistinctAscList :: forall k a. [(k, a)] -> MonoidalMap k a
512513fromDistinctAscList = coerce (M.fromDistinctAscList :: [(k, a)] -> M.Map k a)
513514{-# INLINE fromDistinctAscList #-}
514515
516+fromDistinctList :: forall k a. Ord k => [(k, a)] -> MonoidalMap k a
517+fromDistinctList = coerce (M.fromList :: [(k, a)] -> M.Map k a)
518+{-# INLINE fromDistinctList #-}
519+
515520filter :: forall k a. (a -> Bool) -> MonoidalMap k a -> MonoidalMap k a
516521filter = coerce (M.filter :: (a -> Bool) -> M.Map k a -> M.Map k a)
517522{-# INLINE filter #-}