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 Source

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

Constructors

Bag 

Fields

bag :: Map a [a]
 

Instances

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

Query

size :: Bag a -> Int Source

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

bag ! a finds all elements equal to a.

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

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

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

Return the multiplicity of the given element.

Construction

singleton :: a -> Bag a Source

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

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

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

insert a b = union b (singleton a)

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

fromList = unions . map singleton

Destruction

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

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

toList :: Bag a -> [a] Source

Returns the bag, with duplicates.

keys :: Bag a -> [a] Source

Returns the bag without duplicates.

elems :: Bag a -> [a] Source

Returns the bag, with duplicates.

toAscList :: Bag a -> [a] Source

Traversal

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

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

Instances

Properties

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

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

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

All tests

tests :: IO Bool Source

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.