Agda-2.4.2.3: A dependently typed functional programming language and proof assistant

Safe HaskellNone
LanguageHaskell98

Agda.Utils.Bag

Contents

Description

A simple overlay over Data.Map to manage unordered sets with duplicates.

Synopsis

Documentation

newtype Bag a

A set with duplicates. Faithfully stores elements which are equal with regard to (==).

Constructors

Bag 

Fields

bag :: Map a [a]
 

Instances

Foldable Bag 
Eq a => Eq (Bag a) 
Ord a => Ord (Bag a) 
Show a => Show (Bag a) 
(Ord a, Arbitrary a) => Arbitrary (Bag a) 
Ord a => Monoid (Bag a) 
Null (Bag a) 

Query

null :: Bag a -> Bool

size :: Bag a -> Int

(!) :: Ord a => Bag a -> a -> [a]

bag ! a finds all elements equal to a.

member :: Ord a => a -> Bag a -> Bool

notMember :: Ord a => a -> Bag a -> Bool

count :: Ord a => a -> Bag a -> Int

Return the multiplicity of the given element.

Construction

empty :: Bag a

singleton :: a -> Bag a

union :: Ord a => Bag a -> Bag a -> Bag a

unions :: Ord a => [Bag a] -> Bag a

insert :: Ord a => a -> Bag a -> Bag a

insert a b = union b (singleton a)

fromList :: Ord a => [a] -> Bag a

fromList = unions . map singleton

Destruction

groups :: Bag a -> [[a]]

Returns the elements of the bag, grouped by equality (==).

toList :: Bag a -> [a]

Returns the bag, with duplicates.

keys :: Bag a -> [a]

Returns the bag without duplicates.

elems :: Bag a -> [a]

Returns the bag, with duplicates.

toAscList :: Bag a -> [a]

Traversal

map :: (Ord a, Ord b) => (a -> b) -> Bag a -> Bag b

traverse' :: forall a b m. (Applicative m, Ord b) => (a -> m b) -> Bag a -> m (Bag b)

Instances

Properties

prop_count_insert :: Ord a => a -> Bag a -> Bool

prop_size_union :: Ord a => Bag a -> Bag a -> Bool

prop_size_fromList :: Ord a => [a] -> Bool

prop_keys_fromList :: Ord a => [a] -> Bool

prop_map_id :: Ord a => Bag a -> Bool

prop_map_compose :: (Ord a, Ord b, Ord c) => (b -> c) -> (a -> b) -> Bag a -> Bool

All tests

tests :: IO Bool

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.