-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Beautiful Folding -- -- This package is a playground full of comonadic folds. -- -- This style of fold is documented in "Cellular Automata, Part II: -- PNGs and Moore" -- -- This package can be seen as what happens if you chase Max Rabkin's -- "Beautiful Folding" to its logical conclusion. -- -- More information on this approach can be found in the "Another -- lovely example of type class morphisms" and "More beautiful -- fold zipping" posts by Conal Elliott, as well as in Gabriel -- Gonzales' "Composable Streaming Folds" @package folds @version 0.2 module Data.Fold.Internal -- | Reversed '[]' data SnocList a Snoc :: (SnocList a) -> a -> SnocList a Nil :: SnocList a -- | Strict Maybe data Maybe' a Nothing' :: Maybe' a Just' :: !a -> Maybe' a maybe' :: b -> (a -> b) -> Maybe' a -> b -- | Strict Pair data Pair' a b Pair' :: !a -> !b -> Pair' a b -- | A reified Monoid. newtype N a s N :: a -> N a s runN :: N a s -> a -- | The shape of a foldMap data Tree a Zero :: Tree a One :: a -> Tree a Two :: (Tree a) -> (Tree a) -> Tree a instance Typeable1 SnocList instance Typeable1 Maybe' instance Typeable2 N instance Typeable1 Tree instance Typeable2 Pair' instance Eq a => Eq (SnocList a) instance Ord a => Ord (SnocList a) instance Show a => Show (SnocList a) instance Read a => Read (SnocList a) instance Data a => Data (SnocList a) instance Eq a => Eq (Maybe' a) instance Ord a => Ord (Maybe' a) instance Show a => Show (Maybe' a) instance Read a => Read (Maybe' a) instance Data a => Data (Maybe' a) instance Eq a => Eq (N a s) instance Ord a => Ord (N a s) instance Show a => Show (N a s) instance Read a => Read (N a s) instance (Data a, Data s) => Data (N a s) instance Eq a => Eq (Tree a) instance Ord a => Ord (Tree a) instance Show a => Show (Tree a) instance Read a => Read (Tree a) instance Data a => Data (Tree a) instance (Eq a, Eq b) => Eq (Pair' a b) instance (Ord a, Ord b) => Ord (Pair' a b) instance (Show a, Show b) => Show (Pair' a b) instance (Read a, Read b) => Read (Pair' a b) instance (Data a, Data b) => Data (Pair' a b) instance (Monoid a, Monoid b) => Monoid (Pair' a b) instance Traversable Tree instance Foldable Tree instance Functor Tree instance Reifies * s (a -> a -> a, a) => Monoid (N a s) instance Foldable Maybe' instance Traversable SnocList instance Foldable SnocList instance Functor SnocList module Data.Fold.Class class Choice p => Folding p where prefix = prefixOf folded prefix1 = prefix . One postfix = postfixOf folded postfix1 p = postfix p . One run = runOf folded run1 = run . One prefix :: (Folding p, Foldable t) => t a -> p a b -> p a b prefix1 :: Folding p => a -> p a b -> p a b prefixOf :: Folding p => Fold s a -> s -> p a b -> p a b postfix :: (Folding p, Foldable t) => p a b -> t a -> p a b postfix1 :: Folding p => p a b -> a -> p a b postfixOf :: Folding p => Fold s a -> p a b -> s -> p a b run :: (Folding p, Foldable t) => t a -> p a b -> b run1 :: Folding p => a -> p a b -> b runOf :: Folding p => Fold s a -> s -> p a b -> b filtering :: Folding p => (a -> Bool) -> p a b -> p a b interspersing :: Folding p => a -> p a b -> p a b -- | Lift a Folding into a Prism. -- -- This acts like a generalized notion of "costrength", when applied to a -- Folding, causing it to return the left-most value that fails to -- match the Prism, or the result of accumulating rewrapped in the -- Prism if everything matches. -- --
--   >>> run [Left 1, Left 2, Left 3] $ beneath _Left $ R id (+) 0
--   Left 6
--   
-- --
--   >>> run [Left 1, Right 2, Right 3] $ beneath _Left $ R id (+) 0
--   Right 2
--   
-- --
--   beneath :: Prism s t a b -> p a b -> p s t
--   beneath :: Iso s t a b   -> p a b -> p s t
--   
beneath :: Profunctor p => Overloaded p Mutator s t a b -> p a b -> p s t instance Foldable One module Data.Fold.L data L a b L :: (r -> b) -> (r -> a -> r) -> r -> L a b -- | Construct a Moore machine from a state valuation and transition -- function unfoldL :: (s -> (b, a -> s)) -> s -> L a b instance ComonadApply (L a) instance Apply (L a) instance Extend (L a) instance Monad (L a) instance Bind (L a) instance Applicative (L a) instance Comonad (L a) instance Functor (L a) instance Choice L instance Profunctor L instance Folding L module Data.Fold.L' -- | strict left folds data L' a b L' :: (r -> b) -> (r -> a -> r) -> r -> L' a b -- | Construct a strict Moore machine from a state valuation and transition -- function unfoldL' :: (s -> (b, a -> s)) -> s -> L' a b instance ComonadApply (L' a) instance Apply (L' a) instance Extend (L' a) instance Monad (L' a) instance Bind (L' a) instance Applicative (L' a) instance Comonad (L' a) instance Functor (L' a) instance Choice L' instance Profunctor L' instance Folding L' -- | Unlike L and R this Comonad is based on a -- (->) r Comonad for a Monoid r -- rather than than on the Store r Comonad. module Data.Fold.M -- | A foldMap caught in amber. data M a b M :: (m -> b) -> (a -> m) -> (m -> m -> m) -> m -> M a b instance ComonadApply (M a) instance Apply (M a) instance Extend (M a) instance Monad (M a) instance Bind (M a) instance Applicative (M a) instance Comonad (M a) instance Functor (M a) instance Choice M instance Profunctor M instance Folding M module Data.Fold.R data R a b R :: (r -> b) -> (a -> r -> r) -> r -> R a b instance ComonadApply (R a) instance Apply (R a) instance Extend (R a) instance Applicative (R a) instance Monad (R a) instance Bind (R a) instance Comonad (R a) instance Functor (R a) instance Choice R instance Profunctor R instance Folding R module Data.Fold data L a b L :: (r -> b) -> (r -> a -> r) -> r -> L a b -- | strict left folds data L' a b L' :: (r -> b) -> (r -> a -> r) -> r -> L' a b -- | A foldMap caught in amber. data M a b M :: (m -> b) -> (a -> m) -> (m -> m -> m) -> m -> M a b data R a b R :: (r -> b) -> (a -> r -> r) -> r -> R a b class Choice p => Folding p where prefix = prefixOf folded prefix1 = prefix . One postfix = postfixOf folded postfix1 p = postfix p . One run = runOf folded run1 = run . One prefix :: (Folding p, Foldable t) => t a -> p a b -> p a b prefix1 :: Folding p => a -> p a b -> p a b prefixOf :: Folding p => Fold s a -> s -> p a b -> p a b postfix :: (Folding p, Foldable t) => p a b -> t a -> p a b postfix1 :: Folding p => p a b -> a -> p a b postfixOf :: Folding p => Fold s a -> p a b -> s -> p a b run :: (Folding p, Foldable t) => t a -> p a b -> b run1 :: Folding p => a -> p a b -> b runOf :: Folding p => Fold s a -> s -> p a b -> b filtering :: Folding p => (a -> Bool) -> p a b -> p a b interspersing :: Folding p => a -> p a b -> p a b -- | Lift a Folding into a Prism. -- -- This acts like a generalized notion of "costrength", when applied to a -- Folding, causing it to return the left-most value that fails to -- match the Prism, or the result of accumulating rewrapped in the -- Prism if everything matches. -- --
--   >>> run [Left 1, Left 2, Left 3] $ beneath _Left $ R id (+) 0
--   Left 6
--   
-- --
--   >>> run [Left 1, Right 2, Right 3] $ beneath _Left $ R id (+) 0
--   Right 2
--   
-- --
--   beneath :: Prism s t a b -> p a b -> p s t
--   beneath :: Iso s t a b   -> p a b -> p s t
--   
beneath :: Profunctor p => Overloaded p Mutator s t a b -> p a b -> p s t class AsRM p where asM = asM . asR asR = asR . asM asM :: AsRM p => p a b -> M a b asR :: AsRM p => p a b -> R a b class AsL' p asL' :: AsL' p => p a b -> L' a b instance AsL' L instance AsL' L' instance AsRM L' instance AsRM L instance AsRM M instance AsRM R