-- 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: -- --mappend mempty x = x
mappend x mempty = x
mappend x (mappend y z) = mappend (mappend x y) z
mconcat = foldr mappend mempty
-- 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