-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Generalization of standard Functor, Foldable, and Traversable classes -- -- This package generalizes familiar Functor, Foldable and -- Traversable for the case when a functorial type of kind Type -- -> Type imposes certain constraints on what can be put in. E.g. -- Set can only deal with types that are an instance of Ord -- and therefore cannot be made an instance of Functor. But it can -- be made an instance of a constrained functor with a similar interface -- that this package provides. @package constrained @version 0.1 module Data.Constrained -- | Specification of constrains that a functor might impose on its -- elements. For example, sets typically require that their elements are -- ordered and unboxed vectors require elements to have an instance of -- special class that allows them to be packed in memory. -- -- NB The Constraints type family is associated with a typeclass -- in order to improve type inference. Whenever a typeclass constraint -- will be present, instance is guaranteed to exist and typechecker is -- going to take advantage of that. class Constrained (f :: k2 -> k1) where { type family Constraints (f :: k2 -> k1) :: k2 -> Constraint; } -- | Used to specify values for Constraints type family to indicate -- absence of any constraints (i.e. empty Constraint). class NoConstraints (a :: k) -- | Combine constraints of two functors together to form a bigger set of -- constraints. class (Constraints f a, Constraints g a) => UnionConstraints (f :: k1 -> k2) (g :: k1 -> k2) (a :: k1) -- | Combine constraints for a case when one functors contains the other -- one. class (Constraints f (g a), Constraints g a) => ComposeConstraints (f :: k2 -> k1) (g :: k3 -> k2) (a :: k3) instance forall k3 k2 k1 (f :: k2 -> k1) (g :: k3 -> k2) (a :: k3). (Data.Constrained.Constraints f (g a), Data.Constrained.Constraints g a) => Data.Constrained.ComposeConstraints f g a instance forall k2 k (f :: k -> *) (g :: k2 -> k). (Data.Constrained.Constrained f, Data.Constrained.Constrained g) => Data.Constrained.Constrained (Data.Functor.Compose.Compose f g) instance forall k1 k2 (f :: k1 -> k2) (a :: k1) (g :: k1 -> k2). (Data.Constrained.Constraints f a, Data.Constrained.Constraints g a) => Data.Constrained.UnionConstraints f g a instance forall k2 (f :: k2 -> *) (g :: k2 -> *). (Data.Constrained.Constrained f, Data.Constrained.Constrained g) => Data.Constrained.Constrained (Data.Functor.Product.Product f g) instance forall k2 (f :: k2 -> *) (g :: k2 -> *). (Data.Constrained.Constrained f, Data.Constrained.Constrained g) => Data.Constrained.Constrained (Data.Functor.Sum.Sum f g) instance forall k (a :: k). Data.Constrained.NoConstraints a instance Data.Constrained.Constrained [] instance Data.Constrained.Constrained GHC.Base.NonEmpty instance Data.Constrained.Constrained Data.Functor.Identity.Identity instance Data.Constrained.Constrained ((,) a) instance Data.Constrained.Constrained GHC.Maybe.Maybe instance Data.Constrained.Constrained (Data.Either.Either a) instance Data.Constrained.Constrained (Data.Functor.Const.Const a) instance Data.Constrained.Constrained Control.Applicative.ZipList instance Data.Constrained.Constrained Data.Semigroup.Min instance Data.Constrained.Constrained Data.Semigroup.Max instance Data.Constrained.Constrained Data.Semigroup.First instance Data.Constrained.Constrained Data.Semigroup.Last instance Data.Constrained.Constrained Data.Semigroup.Internal.Dual instance Data.Constrained.Constrained Data.Semigroup.Internal.Sum instance Data.Constrained.Constrained Data.Semigroup.Internal.Product instance forall k2 (f :: k2 -> *). Data.Constrained.Constrained f => Data.Constrained.Constrained (Data.Monoid.Ap f) instance forall k2 (f :: k2 -> *). Data.Constrained.Constrained f => Data.Constrained.Constrained (Data.Semigroup.Internal.Alt f) module Data.Foldable.Constrained -- | Like Foldable but allows elements to have constraints on them. -- Laws are the same. class Constrained f => CFoldable f -- | Combine the elements of a structure using a monoid. cfold :: (CFoldable f, Monoid m, Constraints f m) => f m -> m -- | Map each element of the structure to a monoid, and combine the -- results. cfoldMap :: (CFoldable f, Monoid m, Constraints f a) => (a -> m) -> f a -> m -- | Right-associative fold of a structure. -- -- In the case of lists, cfoldr, when applied to a binary -- operator, a starting value (typically the right-identity of the -- operator), and a list, reduces the list using the binary operator, -- from right to left: -- --
--   cfoldr f z [x1, x2, ..., xn] == x1 `f` (x2 `f` ... (xn `f` z)...)
--   
-- -- Note that, since the head of the resulting expression is produced by -- an application of the operator to the first element of the list, -- cfoldr can produce a terminating expression from an infinite -- list. -- -- For a general CFoldable structure this should be semantically -- identical to, -- --
--   cfoldr f z = foldr f z . ctoList
--   
cfoldr :: (CFoldable f, Constraints f a) => (a -> b -> b) -> b -> f a -> b -- | Right-associative fold of a structure, but with strict application of -- the operator. cfoldr' :: (CFoldable f, Constraints f a) => (a -> b -> b) -> b -> f a -> b -- | Left-associative fold of a structure. -- -- In the case of lists, cfoldl, when applied to a binary -- operator, a starting value (typically the left-identity of the -- operator), and a list, reduces the list using the binary operator, -- from left to right: -- --
--   cfoldl f z [x1, x2, ..., xn] == (...((z `f` x1) `f` x2) `f`...) `f` xn
--   
-- -- Note that to produce the outermost application of the operator the -- entire input list must be traversed. This means that cfoldl' -- will diverge if given an infinite list. -- -- Also note that if you want an efficient left-fold, you probably want -- to use cfoldl' instead of cfoldl. The reason for this is -- that latter does not force the "inner" results (e.g. z f -- x1 in the above example) before applying them to the operator -- (e.g. to (f x2)). This results in a thunk chain -- O(n) elements long, which then must be evaluated from the -- outside-in. -- -- For a general CFoldable structure this should be semantically -- identical to, -- --
--   cfoldl f z = foldl f z . ctoList
--   
cfoldl :: (CFoldable f, Constraints f a) => (b -> a -> b) -> b -> f a -> b -- | Left-associative fold of a structure but with strict application of -- the operator. -- -- This ensures that each step of the fold is forced to weak head normal -- form before being applied, avoiding the collection of thunks that -- would otherwise occur. This is often what you want to strictly reduce -- a finite list to a single, monolithic result (e.g. clength). -- -- For a general CFoldable structure this should be semantically -- identical to, -- --
--   cfoldl f z = foldl' f z . ctoList
--   
cfoldl' :: (CFoldable f, Constraints f a) => (b -> a -> b) -> b -> f a -> b -- | A variant of cfoldr that has no base case, and thus may only be -- applied to non-empty structures. -- --
--   cfoldr1 f = foldr1 f . ctoList
--   
cfoldr1 :: (CFoldable f, Constraints f a) => (a -> a -> a) -> f a -> a -- | A variant of cfoldl that has no base case, and thus may only be -- applied to non-empty structures. -- --
--   cfoldl1 f = foldl1 f . ctoList
--   
cfoldl1 :: (CFoldable f, Constraints f a) => (a -> a -> a) -> f a -> a -- | List of elements of a structure, from left to right. ctoList :: (CFoldable f, Constraints f a) => f a -> [a] -- | Test whether the structure is empty. The default implementation is -- optimized for structures that are similar to cons-lists, because there -- is no general way to do better. cnull :: (CFoldable f, Constraints f a) => f a -> Bool -- | Returns the size/length of a finite structure as an Int. The -- default implementation is optimized for structures that are similar to -- cons-lists, because there is no general way to do better. clength :: (CFoldable f, Constraints f a) => f a -> Int -- | Does the element occur in the structure? celem :: (CFoldable f, Eq a, Constraints f a) => a -> f a -> Bool -- | The largest element of a non-empty structure. cmaximum :: forall a. (CFoldable f, Ord a, Constraints f a) => f a -> a -- | The least element of a non-empty structure. cminimum :: forall a. (CFoldable f, Ord a, Constraints f a) => f a -> a -- | The csum function computes the sum of the numbers of a -- structure. csum :: (CFoldable f, Num a, Constraints f a) => f a -> a -- | The cproduct function computes the product of the numbers of a -- structure. cproduct :: (CFoldable f, Num a, Constraints f a) => f a -> a -- | Monadic fold over the elements of a structure, associating to the -- right, i.e. from right to left. cfoldrM :: (CFoldable f, Monad m, Constraints f a) => (a -> b -> m b) -> b -> f a -> m b -- | Monadic fold over the elements of a structure, associating to the -- left, i.e. from left to right. cfoldlM :: (CFoldable f, Monad m, Constraints f a) => (b -> a -> m b) -> b -> f a -> m b -- | Map each element of a structure to an action, evaluate these actions -- from left to right, and ignore the results. For a version that doesn't -- ignore the results see traverse. ctraverse_ :: (CFoldable f, Applicative f, Constraints f a) => (a -> f b) -> f a -> f () -- | cfor_ is ctraverse_ with its arguments flipped. For a -- version that doesn't ignore the results see cfor. -- --
--   >>> for_ [1..4] print
--   1
--   2
--   3
--   4
--   
cfor_ :: (CFoldable f, Applicative f, Constraints f a) => f a -> (a -> f b) -> f () -- | Map each element of a structure to a monadic action, evaluate these -- actions from left to right, and ignore the results. For a version that -- doesn't ignore the results see mapM. cmapM_ :: (CFoldable f, Monad m, Constraints f a) => (a -> m b) -> f a -> m () -- | cforM_ is cmapM_ with its arguments flipped. For a -- version that doesn't ignore the results see forM. cforM_ :: (CFoldable f, Monad m, Constraints f a) => f a -> (a -> m b) -> m () -- | Evaluate each action in the structure from left to right, and ignore -- the results. For a version that doesn't ignore the results see -- sequenceA. csequenceA_ :: (CFoldable f, Applicative m, Constraints f (m a)) => f (m a) -> m () -- | Evaluate each monadic action in the structure from left to right, and -- ignore the results. For a version that doesn't ignore the results see -- sequence. csequence_ :: (CFoldable f, Monad m, Constraints f a, Constraints f (m a)) => f (m a) -> m () -- | The sum of a collection of actions, generalizing concat. -- -- asum [Just Hello, Nothing, Just World] Just Hello casum :: (CFoldable f, Alternative m, Constraints f (m a)) => f (m a) -> m a -- | The sum of a collection of actions, generalizing concat. cmsum :: (CFoldable f, MonadPlus m, Constraints f (m a)) => f (m a) -> m a -- | The concatenation of all the elements of a container of lists. cconcat :: (CFoldable f, Constraints f [a]) => f [a] -> [a] -- | Map a function over all the elements of a container and concatenate -- the resulting lists. cconcatMap :: (CFoldable f, Constraints f a) => (a -> [b]) -> f a -> [b] -- | cand 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. cand :: (CFoldable f, Constraints f Bool) => f Bool -> Bool -- | cor 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. cor :: (CFoldable f, Constraints f Bool) => f Bool -> Bool -- | Determines whether any element of the structure satisfies the -- predicate. cany :: (CFoldable f, Constraints f a) => (a -> Bool) -> f a -> Bool -- | Determines whether all elements of the structure satisfy the -- predicate. call :: (CFoldable f, Constraints f a) => (a -> Bool) -> f a -> Bool -- | The largest element of a non-empty structure with respect to the given -- comparison function. cmaximumBy :: (CFoldable f, Constraints f a) => (a -> a -> Ordering) -> f a -> a -- | The least element of a non-empty structure with respect to the given -- comparison function. cminimumBy :: (CFoldable f, Constraints f a) => (a -> a -> Ordering) -> f a -> a -- | cnotElem is the negation of celem. cnotElem :: (CFoldable f, Eq a, Constraints f a) => a -> f a -> Bool -- | The cfind 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. cfind :: (CFoldable f, Constraints f a) => (a -> Bool) -> f a -> Maybe a -- | Specification of constrains that a functor might impose on its -- elements. For example, sets typically require that their elements are -- ordered and unboxed vectors require elements to have an instance of -- special class that allows them to be packed in memory. -- -- NB The Constraints type family is associated with a typeclass -- in order to improve type inference. Whenever a typeclass constraint -- will be present, instance is guaranteed to exist and typechecker is -- going to take advantage of that. class Constrained (f :: k2 -> k1) where { type family Constraints (f :: k2 -> k1) :: k2 -> Constraint; } instance Data.Foldable.Constrained.CFoldable [] instance Data.Foldable.Constrained.CFoldable GHC.Base.NonEmpty instance Data.Foldable.Constrained.CFoldable Data.Functor.Identity.Identity instance Data.Foldable.Constrained.CFoldable ((,) a) instance Data.Foldable.Constrained.CFoldable GHC.Maybe.Maybe instance Data.Foldable.Constrained.CFoldable (Data.Either.Either a) instance Data.Foldable.Constrained.CFoldable (Data.Functor.Const.Const a) instance Data.Foldable.Constrained.CFoldable Control.Applicative.ZipList instance Data.Foldable.Constrained.CFoldable Data.Semigroup.Min instance Data.Foldable.Constrained.CFoldable Data.Semigroup.Max instance Data.Foldable.Constrained.CFoldable Data.Semigroup.First instance Data.Foldable.Constrained.CFoldable Data.Semigroup.Last instance Data.Foldable.Constrained.CFoldable Data.Semigroup.Internal.Dual instance Data.Foldable.Constrained.CFoldable Data.Semigroup.Internal.Sum instance Data.Foldable.Constrained.CFoldable Data.Semigroup.Internal.Product instance Data.Foldable.Constrained.CFoldable f => Data.Foldable.Constrained.CFoldable (Data.Monoid.Ap f) instance Data.Foldable.Constrained.CFoldable f => Data.Foldable.Constrained.CFoldable (Data.Semigroup.Internal.Alt f) instance (Data.Foldable.Constrained.CFoldable f, Data.Foldable.Constrained.CFoldable g) => Data.Foldable.Constrained.CFoldable (Data.Functor.Compose.Compose f g) instance (Data.Foldable.Constrained.CFoldable f, Data.Foldable.Constrained.CFoldable g) => Data.Foldable.Constrained.CFoldable (Data.Functor.Product.Product f g) instance (Data.Foldable.Constrained.CFoldable f, Data.Foldable.Constrained.CFoldable g) => Data.Foldable.Constrained.CFoldable (Data.Functor.Sum.Sum f g) module Data.Functor.Constrained -- | Like Functor but allows elements to have constraints on them. -- Laws are the same: -- --
--   cmap id      == id
--   cmap (f . g) == cmap f . cmap g
--   
class Constrained f => CFunctor f cmap :: (CFunctor f, Constraints f a, Constraints f b) => (a -> b) -> f a -> f b cmap_ :: (CFunctor f, Constraints f a, Constraints f b) => a -> f b -> f a cmap :: (CFunctor f, Functor f, Constraints f a, Constraints f b) => (a -> b) -> f a -> f b -- | Used to specify values for Constraints type family to indicate -- absence of any constraints (i.e. empty Constraint). class NoConstraints (a :: k) -- | Specification of constrains that a functor might impose on its -- elements. For example, sets typically require that their elements are -- ordered and unboxed vectors require elements to have an instance of -- special class that allows them to be packed in memory. -- -- NB The Constraints type family is associated with a typeclass -- in order to improve type inference. Whenever a typeclass constraint -- will be present, instance is guaranteed to exist and typechecker is -- going to take advantage of that. class Constrained (f :: k2 -> k1) where { type family Constraints (f :: k2 -> k1) :: k2 -> Constraint; } instance Data.Functor.Constrained.CFunctor [] instance Data.Functor.Constrained.CFunctor GHC.Base.NonEmpty instance Data.Functor.Constrained.CFunctor Data.Functor.Identity.Identity instance Data.Functor.Constrained.CFunctor ((,) a) instance Data.Functor.Constrained.CFunctor GHC.Maybe.Maybe instance Data.Functor.Constrained.CFunctor (Data.Either.Either a) instance Data.Functor.Constrained.CFunctor (Data.Functor.Const.Const a) instance Data.Functor.Constrained.CFunctor Control.Applicative.ZipList instance Data.Functor.Constrained.CFunctor Data.Semigroup.Min instance Data.Functor.Constrained.CFunctor Data.Semigroup.Max instance Data.Functor.Constrained.CFunctor Data.Semigroup.First instance Data.Functor.Constrained.CFunctor Data.Semigroup.Last instance Data.Functor.Constrained.CFunctor Data.Semigroup.Internal.Dual instance Data.Functor.Constrained.CFunctor Data.Semigroup.Internal.Sum instance Data.Functor.Constrained.CFunctor Data.Semigroup.Internal.Product instance Data.Functor.Constrained.CFunctor f => Data.Functor.Constrained.CFunctor (Data.Monoid.Ap f) instance Data.Functor.Constrained.CFunctor f => Data.Functor.Constrained.CFunctor (Data.Semigroup.Internal.Alt f) instance (Data.Functor.Constrained.CFunctor f, Data.Functor.Constrained.CFunctor g) => Data.Functor.Constrained.CFunctor (Data.Functor.Compose.Compose f g) instance (Data.Functor.Constrained.CFunctor f, Data.Functor.Constrained.CFunctor g) => Data.Functor.Constrained.CFunctor (Data.Functor.Product.Product f g) instance (Data.Functor.Constrained.CFunctor f, Data.Functor.Constrained.CFunctor g) => Data.Functor.Constrained.CFunctor (Data.Functor.Sum.Sum f g) module Data.Traversable.Constrained -- | Like Traversable but allows elements to have constraints on -- them. Laws are the same: -- --
--   ctraverse pure == pure
--   ctraverse (f <=< g) == ctraverse f <=< ctraverse g
--   
-- -- NB There's no aplicative version because Vectors from the -- http://hackage.haskell.org/package/vector package only support -- monadic traversals. Since they're one of the main motivation for this -- package, Applicative version of traversals will not exist. class (CFunctor f, CFoldable f) => CTraversable f ctraverse :: (CTraversable f, Constraints f a, Constraints f b, Monad m) => (a -> m b) -> f a -> m (f b) csequence :: (CTraversable f, Constraints f a, Constraints f (m a), Monad m) => f (m a) -> m (f a) ctraverse :: (CTraversable f, Constraints f a, Constraints f b, Monad m, Traversable f) => (a -> m b) -> f a -> m (f b) -- | ctraverse with araguments flipped. cfor :: (CTraversable f, Constraints f a, Constraints f b, Monad m) => f a -> (a -> m b) -> m (f b) -- | Specification of constrains that a functor might impose on its -- elements. For example, sets typically require that their elements are -- ordered and unboxed vectors require elements to have an instance of -- special class that allows them to be packed in memory. -- -- NB The Constraints type family is associated with a typeclass -- in order to improve type inference. Whenever a typeclass constraint -- will be present, instance is guaranteed to exist and typechecker is -- going to take advantage of that. class Constrained (f :: k2 -> k1) where { type family Constraints (f :: k2 -> k1) :: k2 -> Constraint; } instance Data.Traversable.Constrained.CTraversable [] instance Data.Traversable.Constrained.CTraversable GHC.Base.NonEmpty instance Data.Traversable.Constrained.CTraversable Data.Functor.Identity.Identity instance Data.Traversable.Constrained.CTraversable ((,) a) instance Data.Traversable.Constrained.CTraversable GHC.Maybe.Maybe instance Data.Traversable.Constrained.CTraversable (Data.Either.Either a) instance Data.Traversable.Constrained.CTraversable (Data.Functor.Const.Const a) instance Data.Traversable.Constrained.CTraversable Control.Applicative.ZipList instance Data.Traversable.Constrained.CTraversable Data.Semigroup.Min instance Data.Traversable.Constrained.CTraversable Data.Semigroup.Max instance Data.Traversable.Constrained.CTraversable Data.Semigroup.First instance Data.Traversable.Constrained.CTraversable Data.Semigroup.Last instance Data.Traversable.Constrained.CTraversable Data.Semigroup.Internal.Dual instance Data.Traversable.Constrained.CTraversable Data.Semigroup.Internal.Sum instance Data.Traversable.Constrained.CTraversable Data.Semigroup.Internal.Product instance Data.Traversable.Constrained.CTraversable f => Data.Traversable.Constrained.CTraversable (Data.Monoid.Ap f) instance Data.Traversable.Constrained.CTraversable f => Data.Traversable.Constrained.CTraversable (Data.Semigroup.Internal.Alt f) instance (Data.Traversable.Constrained.CTraversable f, Data.Traversable.Constrained.CTraversable g) => Data.Traversable.Constrained.CTraversable (Data.Functor.Compose.Compose f g) instance (Data.Traversable.Constrained.CTraversable f, Data.Traversable.Constrained.CTraversable g) => Data.Traversable.Constrained.CTraversable (Data.Functor.Product.Product f g) instance (Data.Traversable.Constrained.CTraversable f, Data.Traversable.Constrained.CTraversable g) => Data.Traversable.Constrained.CTraversable (Data.Functor.Sum.Sum f g)