-- 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.3 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 => Scan p where prefix1 = prefix . One postfix1 p = postfix p . One run1 = run . One prefix1 :: Scan p => a -> p a b -> p a b postfix1 :: Scan p => p a b -> a -> p a b run1 :: Scan p => a -> p a b -> b interspersing :: Scan p => a -> p a b -> p a b class Scan p => Folding p where prefix = prefixOf folded postfix = postfixOf folded run = runOf folded prefix :: (Folding p, Foldable t) => t 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 postfixOf :: Folding p => Fold s a -> p a b -> s -> p a b run :: (Folding p, Foldable t) => t 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 -- | 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 -- | A Moore Machine 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 instance Scan L module Data.Fold.L' -- | A strict left fold / strict Moore machine 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' instance Scan L' module Data.Fold.L1 -- | A Mealy Machine data L1 a b L1 :: (c -> b) -> (c -> a -> c) -> (a -> c) -> L1 a b instance ArrowChoice L1 instance Choice L1 instance Strong L1 instance Profunctor L1 instance Arrow L1 instance Category L1 instance Semigroupoid L1 instance Monad (L1 a) instance Applicative (L1 a) instance Apply (L1 a) instance Pointed (L1 a) instance Functor (L1 a) instance Scan L1 module Data.Fold.L1' -- | A strict Mealy Machine data L1' a b L1' :: (c -> b) -> (c -> a -> c) -> (a -> c) -> L1' a b instance ArrowChoice L1' instance Choice L1' instance Strong L1' instance Profunctor L1' instance Arrow L1' instance Category L1' instance Semigroupoid L1' instance Monad (L1' a) instance Applicative (L1' a) instance Apply (L1' a) instance Pointed (L1' a) instance Functor (L1' a) instance Scan L1' -- | 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. a.k.a. a monoidal reducer 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 instance Scan M module Data.Fold.M1 -- | A semigroup reducer data M1 a b M1 :: (m -> b) -> (a -> m) -> (m -> m -> m) -> M1 a b instance ArrowChoice M1 instance Choice M1 instance Strong M1 instance Profunctor M1 instance Arrow M1 instance Category M1 instance Semigroupoid M1 instance Monad (M1 a) instance Applicative (M1 a) instance Apply (M1 a) instance Pointed (M1 a) instance Functor (M1 a) instance Scan M1 module Data.Fold.R -- | right folds / a reversed Moore machine 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 instance Scan R module Data.Fold.R1 -- | A reversed Mealy machine data R1 a b R1 :: (c -> b) -> (a -> c -> c) -> (a -> c) -> R1 a b instance ArrowChoice R1 instance Choice R1 instance Strong R1 instance Profunctor R1 instance Arrow R1 instance Category R1 instance Semigroupoid R1 instance Monad (R1 a) instance Applicative (R1 a) instance Apply (R1 a) instance Pointed (R1 a) instance Functor (R1 a) instance Scan R1 module Data.Fold class Choice p => Scan p where prefix1 = prefix . One postfix1 p = postfix p . One run1 = run . One prefix1 :: Scan p => a -> p a b -> p a b postfix1 :: Scan p => p a b -> a -> p a b run1 :: Scan p => a -> p a b -> b interspersing :: Scan p => a -> p a b -> p a b class Scan p => Folding p where prefix = prefixOf folded postfix = postfixOf folded run = runOf folded prefix :: (Folding p, Foldable t) => t 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 postfixOf :: Folding p => Fold s a -> p a b -> s -> p a b run :: (Folding p, Foldable t) => t 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 -- | 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 -- | A Mealy Machine data L1 a b L1 :: (c -> b) -> (c -> a -> c) -> (a -> c) -> L1 a b -- | A strict Mealy Machine data L1' a b L1' :: (c -> b) -> (c -> a -> c) -> (a -> c) -> L1' a b -- | A semigroup reducer data M1 a b M1 :: (m -> b) -> (a -> m) -> (m -> m -> m) -> M1 a b -- | A reversed Mealy machine data R1 a b R1 :: (c -> b) -> (a -> c -> c) -> (a -> c) -> R1 a b -- | A Moore Machine data L a b L :: (r -> b) -> (r -> a -> r) -> r -> L a b -- | A strict left fold / strict Moore machine data L' a b L' :: (r -> b) -> (r -> a -> r) -> r -> L' a b -- | A foldMap caught in amber. a.k.a. a monoidal reducer data M a b M :: (m -> b) -> (a -> m) -> (m -> m -> m) -> m -> M a b -- | right folds / a reversed Moore machine data R a b R :: (r -> b) -> (a -> r -> r) -> r -> R a b 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