Copyright | (C) 2009-2013 Edward Kmett |
---|---|
License | BSD-style (see the file LICENSE) |
Maintainer | Edward Kmett <ekmett@gmail.com> |
Stability | experimental |
Portability | non-portable |
Safe Haskell | None |
Language | Haskell98 |
- class Choice p => Scan p where
- class Scan p => Folding p where
- beneath :: Profunctor p => Optic p Identity s t a b -> p a b -> p s t
- data L1 a b = L1 (c -> b) (c -> a -> c) (a -> c)
- data L1' a b = L1' (c -> b) (c -> a -> c) (a -> c)
- data M1 a b = M1 (m -> b) (a -> m) (m -> m -> m)
- data R1 a b = R1 (c -> b) (a -> c -> c) (a -> c)
- data L a b = L (r -> b) (r -> a -> r) r
- data L' a b = L' (r -> b) (r -> a -> r) r
- data M a b = M (m -> b) (a -> m) (m -> m -> m) m
- data R a b = R (r -> b) (a -> r -> r) r
- class AsRM1 p where
- class AsRM1 p => AsL1' p where
- class AsRM1 p => AsRM p where
- class (AsRM p, AsL1' p) => AsL' p where
Scaners and Foldings
class Choice p => Scan p where Source #
prefix1 :: a -> p a b -> p a b Source #
prefix1 :: Folding p => a -> p a b -> p a b Source #
postfix1 :: p a b -> a -> p a b Source #
postfix1 :: Folding p => p a b -> a -> p a b Source #
run1 :: a -> p a b -> b Source #
Apply a Folding
to a single element of input
run1 :: Folding p => a -> p a b -> b Source #
Apply a Folding
to a single element of input
interspersing :: a -> p a b -> p a b Source #
class Scan p => Folding p where Source #
prefix :: Foldable t => t a -> p a b -> p a b Source #
Partially apply a Folding
to some initial input on the left.
prefixOf :: Fold s a -> s -> p a b -> p a b Source #
postfix :: Foldable t => p a b -> t a -> p a b Source #
postfixOf :: Fold s a -> p a b -> s -> p a b Source #
run :: Foldable t => t a -> p a b -> b Source #
Apply a Folding
to a container full of input:
>>>
run ["hello","world"] $ L id (++) []
"helloworld"
>>>
run [1,2,3] $ L id (+) 0
6
Combinators
beneath :: Profunctor p => Optic p Identity s t a b -> p a b -> p s t Source #
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
Scans
Left Scans
A Mealy Machine
L1 (c -> b) (c -> a -> c) (a -> c) |
Arrow L1 Source # | |
ArrowChoice L1 Source # | |
Corepresentable L1 Source # | |
Profunctor L1 Source # | |
Choice L1 Source # | |
Closed L1 Source # | |
Strong L1 Source # | |
Costrong L1 Source # | |
Scan L1 Source # | |
AsL1' L1 Source # | |
AsRM1 L1 Source # | |
Cosieve L1 NonEmpty Source # | |
Monad (L1 a) Source # | |
Functor (L1 a) Source # | |
MonadFix (L1 a) Source # | |
Applicative (L1 a) Source # | |
Distributive (L1 a) Source # | |
Representable (L1 a) Source # | |
MonadZip (L1 a) Source # | |
Pointed (L1 a) Source # | |
Apply (L1 a) Source # | |
Category * L1 Source # | |
Semigroupoid * L1 Source # | |
MonadReader (NonEmpty a) (L1 a) Source # | |
type Corep L1 Source # | |
type Rep (L1 a) Source # | |
A strict Mealy Machine
L1' (c -> b) (c -> a -> c) (a -> c) |
Arrow L1' Source # | |
ArrowChoice L1' Source # | |
Corepresentable L1' Source # | |
Profunctor L1' Source # | |
Choice L1' Source # | |
Closed L1' Source # | |
Strong L1' Source # | |
Costrong L1' Source # | |
Scan L1' Source # | |
AsL1' L1' Source # | |
AsRM1 L1' Source # | |
Cosieve L1' NonEmpty Source # | |
Monad (L1' a) Source # | |
Functor (L1' a) Source # | |
MonadFix (L1' a) Source # | |
Applicative (L1' a) Source # | |
Distributive (L1' a) Source # | |
Representable (L1' a) Source # | |
Pointed (L1' a) Source # | |
Apply (L1' a) Source # | |
Category * L1' Source # | |
Semigroupoid * L1' Source # | |
MonadReader (NonEmpty a) (L1' a) Source # | |
type Corep L1' Source # | |
type Rep (L1' a) Source # | |
Semigroup Scans
A semigroup reducer
M1 (m -> b) (a -> m) (m -> m -> m) |
Arrow M1 Source # | |
ArrowChoice M1 Source # | |
Corepresentable M1 Source # | |
Profunctor M1 Source # | |
Choice M1 Source # | |
Closed M1 Source # | |
Strong M1 Source # | |
Costrong M1 Source # | |
Scan M1 Source # | |
AsRM1 M1 Source # | |
Cosieve M1 FreeSemigroup Source # | |
Monad (M1 a) Source # | |
Functor (M1 a) Source # | |
MonadFix (M1 a) Source # | |
Applicative (M1 a) Source # | |
Distributive (M1 a) Source # | |
Representable (M1 a) Source # | |
MonadZip (M1 a) Source # | |
Pointed (M1 a) Source # | |
Apply (M1 a) Source # | |
Category * M1 Source # | |
Semigroupoid * M1 Source # | |
MonadReader (FreeSemigroup a) (M1 a) Source # | |
type Corep M1 Source # | |
type Rep (M1 a) Source # | |
Right Scans
A reversed Mealy machine
R1 (c -> b) (a -> c -> c) (a -> c) |
Arrow R1 Source # | |
ArrowChoice R1 Source # | |
Corepresentable R1 Source # | |
Profunctor R1 Source # | |
Choice R1 Source # | |
Closed R1 Source # | |
Strong R1 Source # | |
Costrong R1 Source # | |
Scan R1 Source # | |
AsRM1 R1 Source # | |
Cosieve R1 NonEmpty Source # | |
Monad (R1 a) Source # | |
Functor (R1 a) Source # | |
MonadFix (R1 a) Source # | |
Applicative (R1 a) Source # | |
Distributive (R1 a) Source # | |
Representable (R1 a) Source # | |
MonadZip (R1 a) Source # | |
Pointed (R1 a) Source # | |
Apply (R1 a) Source # | |
Category * R1 Source # | |
Semigroupoid * R1 Source # | |
MonadReader (NonEmpty a) (R1 a) Source # | |
type Corep R1 Source # | |
type Rep (R1 a) Source # | |
Foldings
Left Foldings
A Moore Machine
L (r -> b) (r -> a -> r) r |
Corepresentable L Source # | |
Profunctor L Source # | |
Choice L Source # | |
Closed L Source # | |
Costrong L Source # | |
Folding L Source # | |
Scan L Source # | |
AsL' L Source # | We can convert from a lazy left folding to a strict left folding. |
AsL1' L Source # | |
AsRM L Source # | We can convert from a lazy left folding to a right or monoidal fold |
AsRM1 L Source # | |
Cosieve L [] Source # |
|
Monad (L a) Source # | |
Functor (L a) Source # | |
MonadFix (L a) Source # | |
Applicative (L a) Source # | |
Distributive (L a) Source # | |
Representable (L a) Source # | |
MonadZip (L a) Source # | |
Comonad (L a) Source # | |
ComonadApply (L a) Source # | |
Apply (L a) Source # | |
Bind (L a) Source # | |
Extend (L a) Source # | |
MonadReader [a] (L a) Source # | |
type Corep L Source # | |
type Rep (L a) Source # | |
A strict left fold / strict Moore machine
L' (r -> b) (r -> a -> r) r |
Corepresentable L' Source # | |
Profunctor L' Source # | |
Choice L' Source # | |
Closed L' Source # | |
Costrong L' Source # | |
Folding L' Source # | |
Scan L' Source # | |
AsL' L' Source # | We can convert a lazy fold to itself |
AsL1' L' Source # | |
AsRM L' Source # | We can convert from a strict left folding to a right or monoidal fold |
AsRM1 L' Source # | |
Cosieve L' [] Source # | |
Monad (L' a) Source # | |
Functor (L' a) Source # | |
MonadFix (L' a) Source # | |
Applicative (L' a) Source # | |
Distributive (L' a) Source # | |
Representable (L' a) Source # | |
MonadZip (L' a) Source # | |
Comonad (L' a) Source # | |
ComonadApply (L' a) Source # | |
Apply (L' a) Source # | |
Bind (L' a) Source # | |
Extend (L' a) Source # | |
MonadReader [a] (L' a) Source # | |
type Corep L' Source # | |
type Rep (L' a) Source # | |
Monoidal Foldings
A foldMap
caught in amber. a.k.a. a monoidal reducer
M (m -> b) (a -> m) (m -> m -> m) m |
Corepresentable M Source # | |
Profunctor M Source # | |
Choice M Source # | |
Closed M Source # | |
Costrong M Source # | |
Folding M Source # | |
Scan M Source # | |
AsRM M Source # | We can convert from a monoidal fold to a lazy right fold |
AsRM1 M Source # | |
Cosieve M FreeMonoid Source # | |
Monad (M a) Source # | |
Functor (M a) Source # | |
MonadFix (M a) Source # | |
Applicative (M a) Source # | |
Distributive (M a) Source # | |
Representable (M a) Source # | |
MonadZip (M a) Source # | |
Comonad (M a) Source # | |
ComonadApply (M a) Source # | |
Apply (M a) Source # | |
Bind (M a) Source # | |
Extend (M a) Source # | |
MonadReader (FreeMonoid a) (M a) Source # | |
type Corep M Source # | |
type Rep (M a) Source # | |
Right Foldings
right folds / a reversed Moore machine
R (r -> b) (a -> r -> r) r |
Corepresentable R Source # | |
Profunctor R Source # | |
Choice R Source # | |
Closed R Source # | |
Costrong R Source # | |
Folding R Source # | |
Scan R Source # | |
AsRM R Source # | We can convert from a lazy right fold to a monoidal fold |
AsRM1 R Source # | |
Cosieve R [] Source # | |
Monad (R a) Source # | |
Functor (R a) Source # | |
MonadFix (R a) Source # | |
Applicative (R a) Source # | |
Distributive (R a) Source # | |
Representable (R a) Source # | |
MonadZip (R a) Source # | |
Comonad (R a) Source # | |
ComonadApply (R a) Source # | |
Apply (R a) Source # | |
Bind (R a) Source # | |
Extend (R a) Source # | |
MonadReader [a] (R a) Source # | |
type Corep R Source # | |
type Rep (R a) Source # | |
Homomorphisms
Scan Homomorphisms
We define f
to be a scan homomorphism between p
and q
when:
f :: forall a b. p a b -> q a b
run1
xs (f φ) ≡run1
xs φprefix1
xs (f φ) ≡ f (prefix1
xs φ)postfix1
(f φ) xs ≡ f (postfix1
φ xs)dimap
l r (f φ) ≡ f (dimap
l r φ)pure
a ≡ f (pure
a) f φ<*>
f ψ ≡ f (φ<*>
ψ)return
a ≡ f (return
a) f φ>>=
f . k ≡ f (φ>>=
k)interspersing
a (f φ) ≡ f (interspersing
a φ)
Furthermore,
and left'
(f φ)f (
should agree whenever either answer is left'
φ)Right
and right'
(f φ)f (
should agree whenever either answer is right'
φ)Left
Folding Homomorphisms
We define f
to be a folding homomorphism between p
and q
when
f
is a scan homomorphism and additionally we can satisfy:
run
xs (f φ) ≡run
xs φrunOf
l xs (f φ) ≡runOf
l xs φprefix
xs (f φ) ≡ f (prefix
xs φ)prefixOf
l xs (f φ) ≡ f (prefixOf
l xs φ)postfix
(f φ) xs ≡ f (postfix
φ xs)postfixOf
l (f φ) xs ≡ f (postfixOf
l φ xs)extract
(f φ) ≡extract
φfiltering
p (f φ) ≡ f (filtering
p φ)
Note: A law including extend
is explicitly excluded. To work consistenly
across foldings, use prefix
and postfix
instead.
class AsRM1 p => AsRM p where Source #
asM :: p a b -> M a b Source #
asM
is a folding homomorphism to a monoidal folding
run
xs (asM
φ) ≡run
xs φprefix
xs (asM
φ) ≡asM
(prefix
xs φ)prefixOf
l xs (asM
φ) ≡asM
(prefixOf
l xs φ)postfix
(asM
φ) xs ≡asM
(postfix
φ xs)postfixOf
l (asM
φ) xs ≡asM
(postfixOf
l φ xs)left'
(asM
φ) ≡asM
(left'
φ)right'
(asM
φ) ≡asM
(right'
φ)dimap
l r (asM
φ) ≡asM
(dimap
l r φ)extract
(asM
φ) ≡extract
φpure
a ≡asM
(pure
a)asM
φ<*>
asM
ψ ≡asM
(φ<*>
ψ)return
a ≡asM
(return
a)asM
φ>>=
asM
. k ≡asM
(φ>>=
k)filtering
p (asM
φ) ≡asM
(filtering
p φ)interspersing
a (asM
φ) ≡asM
(interspersing
a φ)
asR :: p a b -> R a b Source #
asR
is a folding homomorphism to a right folding
run
xs (asR
φ) ≡run
xs φprefix
xs (asR
φ) ≡asR
(prefix
xs φ)prefixOf
l xs (asR
φ) ≡asR
(prefixOf
l xs φ)postfix
(asR
φ) xs ≡asR
(postfix
φ xs)postfixOf
l (asR
φ) xs ≡asR
(postfixOf
l φ xs)left'
(asR
φ) ≡asR
(left'
φ)right'
(asR
φ) ≡asR
(right'
φ)dimap
l r (asR
φ) ≡asR
(dimap
l r φ)extract
(asR
φ) ≡extract
φpure
a ≡asR
(pure
a)asR
φ<*>
asR
ψ ≡asR
(φ<*>
ψ)return
a ≡asR
(return
a)asR
φ>>=
asR
. k ≡asR
(φ>>=
k)filtering
p (asR
φ) ≡asR
(filtering
p φ)interspersing
a (asR
φ) ≡asR
(interspersing
a φ)
AsRM L Source # | We can convert from a lazy left folding to a right or monoidal fold |
AsRM L' Source # | We can convert from a strict left folding to a right or monoidal fold |
AsRM M Source # | We can convert from a monoidal fold to a lazy right fold |
AsRM R Source # | We can convert from a lazy right fold to a monoidal fold |
class (AsRM p, AsL1' p) => AsL' p where Source #
asL' :: p a b -> L' a b Source #
asL'
is a folding homomorphism to a strict left folding
run
xs (asL'
φ) ≡run
xs φprefix
xs (asL'
φ) ≡asL'
(prefix
xs φ)prefixOf
l xs (asL'
φ) ≡asL'
(prefixOf
l xs φ)postfix
(asL'
φ) xs ≡asL'
(postfix
φ xs)postfixOf
l (asL'
φ) xs ≡asL'
(postfixOf
l φ xs)left'
(asL'
φ) ≡asL'
(left'
φ)right'
(asL'
φ) ≡asL'
(right'
φ)dimap
l r (asL'
φ) ≡asL'
(dimap
l r φ)extract
(asL'
φ) ≡extract
φpure
a ≡asL'
(pure
a)asL'
φ<*>
asL'
ψ ≡asL'
(φ<*>
ψ)return
a ≡asL'
(return
a)asL'
φ>>=
asL'
. k ≡asL'
(φ>>=
k)filtering
p (asL'
φ) ≡asL'
(filtering
p φ)interspersing
a (asL'
φ) ≡asL'
(interspersing
a φ)