Safe Haskell | None |
---|---|
Language | Haskell2010 |
- newtype ToBeFoldled input = ToBeFoldled (forall output. (output -> input -> output) -> output -> output)
- foldl' :: (output -> input -> output) -> output -> ToBeFoldled input -> output
- fold :: Fold input output -> ToBeFoldled input -> output
- foldable :: Foldable foldable => foldable a -> ToBeFoldled a
Documentation
newtype ToBeFoldled input Source #
A projection on data, which only knows how to execute a strict left-fold.
It is a monad and a monoid, and is very useful for
efficiently aggregating the projections on data intended for left-folding,
since its concatenation (<>
) has complexity of O(1)
.
- Intuition
The intuition of what this abstraction is all about can be derived from lists.
Let's consider the foldl'
function for lists:
foldl' :: (b -> a -> b) -> b -> [a] -> b
If we reverse its parameters we get
foldl' :: [a] -> (b -> a -> b) -> b -> b
Which in Haskell is essentially the same as
foldl' :: [a] -> (forall b. (b -> a -> b) -> b -> b)
We can isolate that part into an abstraction:
newtype ToBeFoldled a = ToBeFoldled (forall b. (b -> a -> b) -> b -> b)
Then we get to this simple morphism:
foldl' :: [a] -> ToBeFoldled a
ToBeFoldled (forall output. (output -> input -> output) -> output -> output) |
foldl' :: (output -> input -> output) -> output -> ToBeFoldled input -> output Source #
Perform a strict left fold
fold :: Fold input output -> ToBeFoldled input -> output Source #
Apply a Gonzalez fold
foldable :: Foldable foldable => foldable a -> ToBeFoldled a Source #
Construct from any foldable