-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | API for collection data structures. -- -- This package provides classes for a consistent API to data structures. -- The behaviour of the interface is specified by QuickCheck properties. -- It is intended as an evolution of the API of the data structures in -- the containers package. @package collections-api @version 1.0.0.0 -- | Class of data structures that can be folded to a summary value. module Data.Collections.Foldable -- | Data structures that can be folded. -- -- Minimal complete definition: foldMap or foldr. -- -- For example, given a data type -- --
-- data Tree a = Empty | Leaf a | Node (Tree a) a (Tree a) ---- -- a suitable instance would be -- --
-- instance Foldable Tree -- foldMap f Empty = mempty -- foldMap f (Leaf x) = f x -- foldMap f (Node l k r) = foldMap f l `mappend` f k `mappend` foldMap f r ---- -- This is suitable even for abstract types, as the monoid is assumed to -- satisfy the monoid laws. class Foldable t a | t -> a fold :: (Foldable t a, Monoid a) => t -> a foldMap :: (Foldable t a, Monoid m) => (a -> m) -> t -> m foldr :: Foldable t a => (a -> b -> b) -> b -> t -> b foldl :: Foldable t a => (b -> a -> b) -> b -> t -> b foldr1 :: Foldable t a => (a -> a -> a) -> t -> a foldl1 :: Foldable t a => (a -> a -> a) -> t -> a null :: Foldable t a => t -> Bool size :: Foldable t a => t -> Int isSingleton :: Foldable t a => t -> Bool -- | Fold over the elements of a structure, associating to the right, but -- strictly. foldr' :: Foldable t a => (a -> b -> b) -> b -> t -> b -- | Fold over the elements of a structure, associating to the left, but -- strictly. foldl' :: Foldable t b => (a -> b -> a) -> a -> t -> a -- | Monadic fold over the elements of a structure, associating to the -- right, i.e. from right to left. foldrM :: (Foldable t a, Monad m) => (a -> b -> m b) -> b -> t -> m b -- | Monadic fold over the elements of a structure, associating to the -- left, i.e. from left to right. foldlM :: (Foldable t b, Monad m) => (a -> b -> m a) -> a -> t -> m a -- | Map each element of a structure to an action, evaluate these actions -- from left to right, and ignore the results. traverse_ :: (Foldable t a, Applicative f) => (a -> f b) -> t -> f () -- | for_ is traverse_ with its arguments flipped. for_ :: (Foldable t a, Applicative f) => t -> (a -> f b) -> f () -- | Evaluate each action in the structure from left to right, and ignore -- the results. sequenceA_ :: (Foldable t (f a), Applicative f) => t -> f () -- | The sum of a collection of actions, generalizing concat. asum :: (Foldable t (f a), Alternative f) => t -> f a -- | Map each element of a structure to a monadic action, evaluate these -- actions from left to right, and ignore the results. mapM_ :: (Foldable t a, Monad m) => (a -> m b) -> t -> m () -- | forM_ is mapM_ with its arguments flipped. forM_ :: (Foldable t a, Monad m) => t -> (a -> m b) -> m () -- | Evaluate each monadic action in the structure from left to right, and -- ignore the results. sequence_ :: (Foldable t (m a), Monad m) => t -> m () -- | The sum of a collection of actions, generalizing concat. msum :: (Foldable t (m a), MonadPlus m) => t -> m a -- | List of elements of a structure. toList :: Foldable t a => t -> [a] -- | and returns the conjunction of a container of Bools. For the -- result to be True, the container must be finite; False, -- however, results from a False value finitely far from the left -- end. and :: Foldable t Bool => t -> Bool -- | or returns the disjunction of a container of Bools. For the -- result to be False, the container must be finite; True, -- however, results from a True value finitely far from the left -- end. or :: Foldable t Bool => t -> Bool -- | Determines whether any element of the structure satisfies the -- predicate. any :: Foldable t a => (a -> Bool) -> t -> Bool -- | Determines whether all elements of the structure satisfy the -- predicate. all :: Foldable t a => (a -> Bool) -> t -> Bool -- | The sum function computes the sum of the numbers of a -- structure. sum :: (Foldable t a, Num a) => t -> a -- | The product function computes the product of the numbers of a -- structure. product :: (Foldable t a, Num a) => t -> a -- | The largest element of the structure. maximum :: (Foldable t a, Ord a) => t -> a -- | The largest element of a non-empty structure with respect to the given -- comparison function. maximumBy :: Foldable t a => (a -> a -> Ordering) -> t -> a -- | The least element of a non-null structure. minimum :: (Foldable t a, Ord a) => t -> a -- | The least element of a non-empty structure with respect to the given -- comparison function. minimumBy :: Foldable t a => (a -> a -> Ordering) -> t -> a -- | Does the element occur in the structure? elem :: (Foldable t a, Eq a) => a -> t -> Bool -- | notElem is the negation of elem. notElem :: (Foldable t a, Eq a) => a -> t -> Bool -- | The find function takes a predicate and a structure and returns -- the leftmost element of the structure matching the predicate, or -- Nothing if there is no such element. find :: Foldable t a => (a -> Bool) -> t -> Maybe a instance Ix i => Foldable (Array i a) (i, a) instance Foldable [a] a instance Foldable (Maybe a) a -- | This module defines a class framework for collection types. It -- provides: -- --
-- singleton a == insert a empty ---- --
-- insertMany l c == Foldable.foldr insert c l ---- --
-- insertManySorted l c == Foldable.foldr insert c l -- where l = List.sort l0 --unfoldable_properties :: (Arbitrary c, Arbitrary a, Ord a, Show a, Show c, Eq c, Eq a, Unfoldable c a) => c -> [(Property, String)] -- | foldable_properties returns the following properties: -- --
-- size c == foldr (const (+1)) 0 c ---- --
-- null c <==> all (const False) c ---- --
-- isSingleton c <==> size c == 1 ---- --
-- c1 == c2 ==> elem x c1 == elem x c2 -- note that the order of folding is not enforced, and that the converse is not true --foldable_properties :: (Arbitrary c, Arbitrary a, Show a, Show c, Eq c, Eq a, Foldable c a) => c -> [(Property, String)] -- | collection_properties returns the following properties: -- --
-- foldr insert empty c == c ---- --
-- null empty ---- --
-- a `elem` (insert a c) -- insert puts the element in the collection ---- --
-- a /= a' ==> (a' `elem` c <== a' `elem` (insert a c)) -- insert does not insert other elements ---- --
-- let c' = insert a c in x `elem` c && y `elem` c ==> x `elem` c' || y `elem` c' -- insert alters at most one element ---- --
-- (a `elem` filter f c) <==> ((a `elem` c) && f a) --collection_properties :: (CoArbitrary i, Arbitrary c, Arbitrary i, Show i, Show c, Eq c, Eq i, Collection c i) => c -> [(Property, String)] -- | map_properties returns the following properties: -- --
-- lookup k (alter f k m) == f (lookup k m) ---- --
-- lookup k (mapWithKey f m) == fmap (f k) (lookup k m) ---- --
-- lookup k (unionWith f m1 m2) == case (lookup k m1, lookup k m2) of -- (Nothing,Nothing) -> Nothing -- (Just x, Nothing) -> Just x -- (Nothing,Just x) -> Just x -- (Just x, Just y) -> Just (f x y) ---- --
-- lookup k (intersectionWith f m1 m2) == case (lookup k m1, lookup k m2) of -- (Just x, Just y) -> Just (f x y) -- _ -> Nothing ---- --
-- lookup k (differenceWith f m1 m2) == case (lookup k m1, lookup k m2) of -- (Just x, Nothing) -> Just x -- (Just x, Just y) -> f x y -- (Nothing, _) -> Nothing ---- --
-- isSubmapBy f m1 m2 <==> differenceWith (\x y->if f x y then Nothing else Just v) m1 m2 == mempty ---- --
-- isProperSubmapBy f m1 m2 <==> isSubmapBy f m1 m2 && m1 /= m2 ---- --
-- insertWith f k a m == alter (\x -> Just $ case x of {Nothing->a;Just a' -> f a a'}) k m
--
--
-- -- fromFoldableWith f l == foldr (uncurry (insertWith f)) mempty l ---- --
-- delete k m == alter (const Nothing) k m ---- --
-- member k m <==> isJust (lookup k m) ---- --
-- union m1 m2 == unionWith const m1 m2 ---- --
-- intersection m1 m2 == intersectionWith const m1 m2 ---- --
-- difference m1 m2 == differenceWith (\_ _ -> Nothing) m1 m2 ---- --
-- isSubset m1 m2 <==> isSubmapBy (\_ _ -> True) m1 m2 ---- --
-- isProperSubset m1 m2 <==> isProperSubmapBy (\_ _ -> True) m1 m2 ---- --
-- lookup k mempty == Nothing ---- --
-- mappend m1 m2 == union m1 m2 ---- --
-- c1 == c2 ==> lookup x c1 == lookup x c2 -- should really be: c1 == c2 <==> forall x. lookup x c1 == lookup x c2 --map_properties :: (CoArbitrary v, CoArbitrary k, Arbitrary m, Arbitrary k, Arbitrary v, Show k, Show v, Show m, Eq m, Eq v, Map m k v) => m -> [(Property, String)] -- | map_unfold_properties returns the following properties: -- --
-- mempty == empty ---- --
-- insert (k,v) m == insertWith (\x _ -> x) k v m --map_unfold_properties :: (Arbitrary m, Arbitrary k, Arbitrary v, Show k, Show v, Show m, Eq m, Eq v, Eq k, Map m k v, Collection m (k, v)) => m -> [(Property, String)] -- | set_unfold_properties returns the following properties: -- --
-- mempty == empty ---- --
-- insert k m == insertWith (\x _->x) k () m --set_unfold_properties :: (Arbitrary m, Arbitrary k, Show k, Show m, Eq m, Eq k, Map m k (), Unfoldable m k) => m -> [(Property, String)] -- | map_fold_properties returns the following properties: -- --
-- maybeToList (lookup k m) == map snd (List.filter ((== k) . fst) (toList m)) ---- --
-- sizeExcept (alter f k m) == sizeExcept m -- where sizeExcept m = size m - maybe 0 (const 1) (lookup k m) --map_fold_properties :: (CoArbitrary v, Arbitrary m, Arbitrary k, Arbitrary v, Show k, Show v, Show m, Eq m, Eq v, Eq k, Map m k v, Collection m (k, v)) => m -> [(Property, String)] -- | set_fold_properties returns the following properties: -- --
-- maybeToList (lookup k m) == map (const ()) (List.filter (== k) (toList m)) ---- --
-- sizeExcept (alter f k m) == sizeExcept m -- where sizeExcept m = size m - maybe 0 (const 1) (lookup k m) --set_fold_properties :: (Arbitrary m, Arbitrary k, Show k, Show m, Eq m, Eq k, Map m k (), Foldable m k) => m -> [(Property, String)] -- | indexed_map_properties returns the following properties: -- --
-- k `inDomain` m <==> k `member` m ---- --
-- case lookup k m of {Just x -> x == index k m; _ -> True}
--
indexed_map_properties :: (Arbitrary m, Arbitrary k, Arbitrary v, Show k, Show v, Show m, Eq m, Eq v, Map m k v, Indexed m k v) => m -> [(Property, String)]
-- | sequence_properties returns the following properties:
--
-- -- foldMap f empty == mempty ---- --
-- foldMap f (x <| s) == f x `mappend` foldMap f s ---- --
-- foldMap f (s |> x) == foldMap f s `mappend` f x ---- --
-- foldMap f (s >< t) == foldMap f s `mappend` foldMap f t ---- --
-- front empty == Nothing ---- --
-- front (x <| s) == Just (x,s) ---- --
-- front (s |> x) == case front s of {Nothing -> Just (x, empty); Just (x',s') -> Just (x', s' |> x)}
--
--
--
-- front (s >< t) == case front s of {Nothing -> front t; Just (x',s') -> Just (x', s' >< t)}
--
--
-- -- back empty == Nothing ---- --
-- back (s |> x) == Just (s,x) ---- --
-- back (x <| s) == case back s of {Nothing -> Just (empty, x); Just (s',x') -> Just (x <| s', x')}
--
--
--
-- back (t >< s) == case back s of {Nothing -> back t; Just (s',x') -> Just (t >< s', x')}
--
--
-- -- drop 0 s == s ---- --
-- n>0 ==> drop (n+1) s == case front (drop n s) of Nothing -> empty; Just (_,s') -> s' ---- --
-- take 0 s == empty ---- --
-- n>0 ==> take (n+1) s == case front s of Nothing -> empty; Just (x,s') -> x <| take n s' ---- --
-- foldMap f (reverse s) == getDual (foldMap (Dual . f) s) ---- --
-- mempty == empty ---- --
-- s1 == s2 ==> foldMap f s1 == foldMap f s2 --sequence_properties :: (Arbitrary s, Arbitrary a, Show s, Show a, Eq s, Eq a, Sequence s a) => s -> [(Property, String)] -- | indexed_properties returns the following properties: -- --
-- k `inDomain` m ==> index k (adjust f k m) == f (index k m) --indexed_properties :: (CoArbitrary v, Arbitrary m, Arbitrary k, Arbitrary v, Show k, Show v, Show m, Eq m, Eq v, Indexed m k v) => m -> [(Property, String)] -- | indexed_sequence_properties returns the following properties: -- --
-- k `inDomain` s <==> k >= 0 && k < size s ---- --
-- k `inDomain` s ==> index (k+1) (x <| s) == index k s ---- --
-- index 0 (x <| s) == x ---- --
-- k `inDomain` s ==> index k (s |> x) == index k s ---- --
-- index (size s) (s |> x) == x ---- --
-- k `inDomain` t ==> index (k+size s) (s >< t) == index k t ---- --
-- k `inDomain` s ==> index k (s >< t) == index k s --indexed_sequence_properties :: (Arbitrary s, Arbitrary a, Show s, Show a, Eq s, Eq a, Sequence s a, Indexed s Int a) => s -> [(Property, String)] instance Show (a -> b)