-- 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.1 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 -- | 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 instance Foldable SnocList 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 instance Foldable SnocList 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 Traversable Tree instance Foldable Tree instance Functor Tree instance Reifies * s (a -> a -> a, a) => Monoid (N a s) 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 -- | 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