summaryrefslogtreecommitdiff
path: root/src/full/Agda/Utils/Bag.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/full/Agda/Utils/Bag.hs')
-rw-r--r--src/full/Agda/Utils/Bag.hs72
1 files changed, 5 insertions, 67 deletions
diff --git a/src/full/Agda/Utils/Bag.hs b/src/full/Agda/Utils/Bag.hs
index 002ba8d..310a970 100644
--- a/src/full/Agda/Utils/Bag.hs
+++ b/src/full/Agda/Utils/Bag.hs
@@ -1,6 +1,5 @@
{-# LANGUAGE CPP #-}
{-# LANGUAGE ScopedTypeVariables #-}
-{-# LANGUAGE TemplateHaskell #-}
-- | A simple overlay over Data.Map to manage unordered sets with duplicates.
@@ -16,12 +15,11 @@ import Data.Functor.Identity
import qualified Data.List as List
import Data.Map (Map)
import qualified Data.Map as Map
-import Data.Monoid
+import Data.Semigroup
import qualified Data.Set as Set
import Data.Traversable
import Agda.Utils.Functor
-import Agda.Utils.QuickCheck
#include "undefined.h"
import Agda.Utils.Impossible
@@ -142,9 +140,12 @@ traverse' f = (Bag . Map.fromListWith (++)) <.> traverse trav . Map.elems . bag
instance Show a => Show (Bag a) where
showsPrec _ (Bag b) = ("Agda.Utils.Bag.Bag (" ++) . showsPrec 0 b . (')':)
+instance Ord a => Semigroup (Bag a) where
+ (<>) = union
+
instance Ord a => Monoid (Bag a) where
mempty = empty
- mappend = union
+ mappend = (<>)
mconcat = unions
instance Foldable Bag where
@@ -152,66 +153,3 @@ instance Foldable Bag where
-- not a Functor (only works for 'Ord'ered types)
-- not Traversable (only works for 'Ord'ered types)
-
-------------------------------------------------------------------------
--- * Properties
-------------------------------------------------------------------------
-
-instance (Ord a, Arbitrary a) => Arbitrary (Bag a) where
- arbitrary = fromList <$> arbitrary
-
-prop_count_empty :: Ord a => a -> Bool
-prop_count_empty a = count a empty == 0
-
-prop_count_singleton :: Ord a => a -> Bool
-prop_count_singleton a = count a (singleton a) == 1
-
-prop_count_insert :: Ord a => a -> Bag a -> Bool
-prop_count_insert a b = count a (insert a b) == 1 + count a b
-
-prop_size_union :: Ord a => Bag a -> Bag a -> Bool
-prop_size_union b c = size (b `union` c) == size b + size c
-
-prop_size_fromList :: Ord a => [a] -> Bool
-prop_size_fromList l = size (fromList l) == length l
-
-prop_fromList_toList :: Ord a => Bag a -> Bool
-prop_fromList_toList b = fromList (toList b) == b
-
-prop_toList_fromList :: Ord a => [a] -> Bool
-prop_toList_fromList l = toList (fromList l) == List.sort l
-
-prop_keys_fromList :: Ord a => [a] -> Bool
-prop_keys_fromList l = keys (fromList l) == Set.toList (Set.fromList l)
-
-prop_nonempty_groups :: Bag a -> Bool
-prop_nonempty_groups b = all (not . List.null) $ groups b
-
-prop_map_id :: Ord a => Bag a -> Bool
-prop_map_id b = map id b == b
-
-prop_map_compose :: (Ord b, Ord c) =>
- (b -> c) -> (a -> b) -> Bag a -> Bool
-prop_map_compose f g b = map f (map g b) == map (f . g) b
-
-prop_traverse_id :: Ord a => Bag a -> Bool
-prop_traverse_id b = traverse' Identity b == Identity b
-
-------------------------------------------------------------------------
--- * All tests
-------------------------------------------------------------------------
-
--- Template Haskell hack to make the following $quickCheckAll work
--- under ghc-7.8.
-return [] -- KEEP!
-
--- | All tests as collected by 'quickCheckAll'.
---
--- Using 'quickCheckAll' is convenient and superior to the manual
--- enumeration of tests, since the name of the property is
--- added automatically.
-
-tests :: IO Bool
-tests = do
- putStrLn "Agda.Utils.Favorites"
- $quickCheckAll