-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Fold function applications. Framework for variadic functions. -- -- Fold function applications. Framework for variadic functions. @package data-foldapp @version 0.1.0.0 -- | The most generic definitions for folding function applications. module Data.FoldApp.Generic -- | Class of constraints which feature a function to convert a value of -- one type to a value of another. class Converter (conv :: * -> * -> Constraint) convert :: (Converter conv, conv a b) => a -> b -- | Class defining left-associative folds of function applications. No -- other instances need be defined. class (Converter conv, Infer conv p r f) => FoldlApp (conv :: * -> * -> Constraint) (p :: *) (r :: *) (f :: *) -- | Left-associative fold of function applications. foldlApp :: FoldlApp conv p r f => (r -> p -> r) -> r -> f -- | Class defining right-associative folds of function applications. No -- other instances need be defined. class (Converter conv, Infer conv p r f) => FoldrApp (conv :: * -> * -> Constraint) (p :: *) (r :: *) (f :: *) -- | The Monad class defines the basic operations over a -- monad, a concept from a branch of mathematics known as -- category theory. From the perspective of a Haskell programmer, -- however, it is best to think of a monad as an abstract datatype -- of actions. Haskell's do expressions provide a convenient -- syntax for writing monadic expressions. -- -- Instances of Monad should satisfy the following laws: -- -- -- -- Furthermore, the Monad and Applicative operations should -- relate as follows: -- -- -- -- The above laws imply: -- -- -- -- and that pure and (<*>) satisfy the applicative -- functor laws. -- -- The instances of Monad for lists, Maybe and IO -- defined in the Prelude satisfy these laws. class Applicative m => Monad (m :: * -> *) -- | Monadic left-associative fold of function applications. foldlMApp :: forall conv m p r f. (Monad m, FoldlApp conv p (m r) f) => (r -> p -> m r) -> r -> f -- | Right-associative fold of function applications. foldrApp :: forall conv p r f. FoldrApp conv p r f => (p -> r -> r) -> r -> f -- | Monadic right-associative fold of function applications. foldrMApp :: forall conv m p r f. (Monad m, FoldrApp conv p (m r) f) => (p -> r -> m r) -> r -> f instance Data.FoldApp.Generic.Converter (Data.Type.Equality.~) instance (Data.FoldApp.Generic.Converter conv, Data.FoldApp.Generic.Infer conv p r r) => Data.FoldApp.Generic.FoldlApp conv p r r instance (Data.FoldApp.Generic.Converter conv, Data.FoldApp.Generic.Infer conv p r (x -> f), Data.FoldApp.Generic.FoldlApp conv p r f) => Data.FoldApp.Generic.FoldlApp conv p r (x -> f) instance (Data.FoldApp.Generic.Converter conv, Data.FoldApp.Generic.Infer conv p r r) => Data.FoldApp.Generic.FoldrApp conv p r r instance (Data.FoldApp.Generic.Converter conv, Data.FoldApp.Generic.Infer conv p r (x -> f), Data.FoldApp.Generic.FoldrApp conv p r f) => Data.FoldApp.Generic.FoldrApp conv p r (x -> f) -- | Specialised functions for folds of function applications. The -- converter has been specialised to the identity converter. module Data.FoldApp.Identity -- | Data.FoldApp.FoldlApp with the identity converter chosen. type FoldlApp p r f = FoldlApp (~) p r f -- | Data.FoldApp.FoldrAPp with the identity converter chosen. type FoldrApp p r f = FoldrApp (~) p r f -- | Left-associative fold of function applications. foldlApp :: forall p r f. (FoldlApp p r f) => (r -> p -> r) -> r -> f -- | Monadic left-associative fold of function applications. foldlMApp :: forall m p r f. (Monad m, FoldlApp p (m r) f) => (r -> p -> m r) -> r -> f -- | Right-associative fold of function applications. foldrApp :: forall p r f. FoldrApp p r f => (p -> r -> r) -> r -> f -- | Monadic right-associative fold of function applications. foldrMApp :: forall m p r f. (Monad m, FoldrApp p (m r) f) => (p -> r -> m r) -> r -> f -- | The Monad class defines the basic operations over a -- monad, a concept from a branch of mathematics known as -- category theory. From the perspective of a Haskell programmer, -- however, it is best to think of a monad as an abstract datatype -- of actions. Haskell's do expressions provide a convenient -- syntax for writing monadic expressions. -- -- Instances of Monad should satisfy the following laws: -- -- -- -- Furthermore, the Monad and Applicative operations should -- relate as follows: -- -- -- -- The above laws imply: -- -- -- -- and that pure and (<*>) satisfy the applicative -- functor laws. -- -- The instances of Monad for lists, Maybe and IO -- defined in the Prelude satisfy these laws. class Applicative m => Monad (m :: * -> *) -- | Module of variadic functions. -- -- All types used are re-exported. module Data.FoldApp.Function -- | A monoid on applicative functors. -- -- If defined, some and many should be the least solutions -- of the equations: -- -- class Applicative f => Alternative (f :: * -> *) data Bool :: * -- | Data.FoldApp.FoldlApp with the identity converter chosen. type FoldlApp p r f = FoldlApp (~) p r f -- | Data.FoldApp.FoldrAPp with the identity converter chosen. type FoldrApp p r f = FoldrApp (~) p r f -- | A map of integers to values a. data IntMap a :: * -> * -- | A set of integers. data IntSet :: * -- | A Map from keys k to values a. data Map k a :: * -> * -> * -- | Monads that also support choice and failure. class (Alternative m, Monad m) => MonadPlus (m :: * -> *) -- | The class of monoids (types with an associative binary operation that -- has an identity). Instances should satisfy the following laws: -- -- -- -- The method names refer to the monoid of lists under concatenation, but -- there are many other instances. -- -- Some types can be viewed as a monoid in more than one way, e.g. both -- addition and multiplication on numbers. In such cases we often define -- newtypes and make those instances of Monoid, e.g. -- Sum and Product. class Monoid a -- | Non-empty (and non-strict) list type. data NonEmpty a :: * -> * -- | Basic numeric class. class Num a -- | The Ord class is used for totally ordered datatypes. -- -- Instances of Ord can be derived for any user-defined datatype -- whose constituent types are in Ord. The declared order of the -- constructors in the data declaration determines the ordering in -- derived Ord instances. The Ordering datatype allows a -- single comparison to determine the precise ordering of two objects. -- -- Minimal complete definition: either compare or <=. -- Using compare can be more efficient for complex types. class Eq a => Ord a data Ordering :: * -- | General-purpose finite sequences. data Seq a :: * -> * -- | A set of values a. data Set a :: * -> * -- | True if all arguments are True, False otherwise. allOf :: FoldrApp Bool Bool f => f -- | True if all arguments map to True, False otherwise. allOfBy :: FoldlApp a Bool f => (a -> Bool) -> f -- | Concatentate all arguments with <|>. asumOf :: forall a f g. (Alternative f, FoldrApp (f a) (f a) g) => g -- | Concatenate all arguments with <|> in reverse order. dualAsumOf :: forall a f g. (Alternative f, FoldrApp (f a) (f a) g) => g -- | Concatenate all argments with mappend in reverse order. dualFoldOf :: forall a f. (Monoid a, FoldlApp a a f) => f -- | Concatenate all arguments with mplus in reverse order. dualMsumOf :: forall a m f. (MonadPlus m, FoldrApp (m a) (m a) f) => f -- | Returns the first argument. firstOf :: forall a f. FoldlApp a a f => a -> f -- | Concatenate all arguments with mappend. foldOf :: forall a f. (Monoid a, FoldrApp a a f) => f -- | Form an IntSet from all arguments. intSetOf :: forall f. FoldlApp Key IntSet f => f -- | Returns the last argument. lastOf :: forall a f. FoldlApp a a f => a -> f -- | Form a lazy IntMap from all arguments. lazyIntMapOf :: forall a f. FoldlApp (Key, a) (IntMap a) f => f -- | Form a lazy Map from all arguments. lazyMapOf :: forall k a f. (Ord k, FoldlApp (k, a) (Map k a) f) => f -- | Form a list from all arguments. listOf :: forall a f. FoldrApp a [a] f => f -- | Return the largest argument. maxOf :: forall a f. (Ord a, FoldlApp a a f) => a -> f -- | Return the largest argument by the given comparator. maxOfBy :: forall a f. (Ord a, FoldlApp a a f) => (a -> a -> Ordering) -> a -> f -- | Return the smallest argument. minOf :: forall a f. (Ord a, FoldlApp a a f) => a -> f -- | Return the smallest argument by the given comparator. minOfBy :: forall a f. (Ord a, FoldlApp a a f) => (a -> a -> Ordering) -> a -> f -- | Concatentate all arguments with mplus. msumOf :: forall a m f. (MonadPlus m, FoldrApp (m a) (m a) f) => f -- | Form a NonEmpty list from all arguments. nonEmptyOf :: FoldrApp a (NonEmpty a) f => a -> f -- | Return the product of all arguments. productOf :: forall a f. (Num a, FoldlApp a a f) => f -- | Form a NonEmpty list in reverse order from all arguments. reverseNonEmptyOf :: FoldlApp a (NonEmpty a) f => a -> f -- | Form a list in reverse order from all arguments. reverseOf :: forall a f. FoldlApp a [a] f => f -- | Form a Seq in reverse order from all arguments. reverseSeqOf :: forall a f. FoldlApp a (Seq a) f => f -- | Form a Seq from all arguments. seqOf :: forall a f. FoldlApp a (Seq a) f => f -- | Form a Set from all arguments. setOf :: forall a f. (Ord a, FoldlApp a (Set a) f) => f -- | Form a strict IntMap from all arguments. strictIntMapOf :: forall a f. FoldlApp (Key, a) (IntMap a) f => f -- | Form a strict Map from all arguments. strictMapOf :: forall k a f. (Ord k, FoldlApp (k, a) (Map k a) f) => f -- | Return the sum of all arguments. sumOf :: forall a f. (Num a, FoldlApp a a f) => f -- | This package provides a framework for constructing variadic functions -- as folds over function applications. -- -- For example, a variadic function f may be reduced like this: -- --
--   f a b c
--   ≡ foldlApp @(~) f' z a b c
--   ≡ f' (f' (f' z a) b) c
--   
-- -- Both left and right associative folds are available. -- -- This module re-exports Data.FoldApp.Identity which assumes the -- identity conversion for arguments. Data.FoldApp.Generic -- provides the generalised folds where a different converter may be -- given. Conversion allows for folding over differently-typed arguments -- by converting them to a common type. -- -- Data.FoldApp.Function contains several variadic functions which -- may be useful as examples or in your programs. -- -- Folds cannot be defined to return functions. This is because the -- parameters intended for the returned function become confused with the -- parameters intended for folding. This weakness can be circumvented by -- wrapping and unwrapping returned functions with a newtype at the cost -- of inconvenience. -- -- If a type inference problem arises, you possibly need to provide an -- annotation for some arguments or an annotation for the return type. -- For example, without any other typing context the following is -- ambiguous … -- --
--   listOf "hello" "sailor!"
--   
-- -- … because it is not known how many more arguments should be accepted. -- An annotation such as the following fixes this problem … -- --
--   listOf "hello" "sailor!" :: String -> [String]
--   
-- -- … saying one more String argument must be given and a -- [String] will be returned. module Data.FoldApp