Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- type Fold1 s a = forall p. (Choice p, Representable p, Apply (Rep p), forall x. Contravariant (p x)) => Optic p s s a a
- fold1_ :: Foldable1 f => (s -> f a) -> Fold1 s a
- folding1 :: Traversable1 f => (s -> a) -> Fold1 (f s) a
- fold1Vl :: (forall f. Apply f => (a -> f b) -> s -> f t) -> Fold1 s a
- toFold1 :: AView s a -> Fold1 s a
- cloneFold1 :: Semigroup a => AFold1 a s a -> View s a
- type Cofold1 t b = forall p. (Cochoice p, Corepresentable p, Apply (Corep p), Bifunctor p) => Optic p t t b b
- cofold1Vl :: (forall f. Apply f => (f a -> b) -> f s -> t) -> Cofold1 t b
- cofolding1 :: Distributive f => (b -> t) -> Cofold1 (f t) b
- folded1 :: Traversable1 f => Fold1 (f a) a
- cofolded1 :: Distributive f => Cofold1 (f b) b
- folded1_ :: Foldable1 f => Fold1 (f a) a
- nonunital :: Foldable f => Foldable1 g => Monoid r => Semiring r => AFold r (f (g a)) a
- presemiring :: Foldable1 f => Foldable1 g => Semiring r => AFold1 r (f (g a)) a
- summed1 :: Foldable1 f => Semigroup r => AFold1 r (f a) a
- multiplied1 :: Foldable1 f => Semiring r => AFold1 r (f a) a
- withFold1 :: Semigroup r => AFold1 r s a -> (a -> r) -> s -> r
- withCofold1 :: ACofold1 r t b -> (r -> b) -> r -> t
- folds1 :: Semigroup a => AFold1 a s a -> s -> a
- cofolds1 :: ACofold1 b t b -> b -> t
- folds1p :: Semiring r => AFold (Prod r) s a -> (a -> r) -> s -> r
- nelists :: AFold1 (Nedl a) s a -> s -> NonEmpty a
- type FoldRep r = Star (Const r)
- type AFold1 r s a = Optic' (FoldRep r) s a
- type Cofold1Rep r = Costar (Const r)
- type ACofold1 r t b = Optic' (Cofold1Rep r) t b
- afold1 :: Semigroup r => ((a -> r) -> s -> r) -> AFold1 r s a
- acofold1 :: ((r -> b) -> r -> t) -> ACofold1 r t b
- newtype Star (f :: Type -> Type) d c = Star {
- runStar :: d -> f c
- newtype Costar (f :: Type -> Type) d c = Costar {
- runCostar :: f d -> c
- class (Sieve p (Rep p), Strong p) => Representable (p :: Type -> Type -> Type) where
- class (Cosieve p (Corep p), Costrong p) => Corepresentable (p :: Type -> Type -> Type) where
- class Contravariant (f :: Type -> Type) where
- class Bifunctor (p :: Type -> Type -> Type) where
- newtype Nedl a = Nedl {}
Fold1 & Ixfold1
type Fold1 s a = forall p. (Choice p, Representable p, Apply (Rep p), forall x. Contravariant (p x)) => Optic p s s a a Source #
folding1 :: Traversable1 f => (s -> a) -> Fold1 (f s) a Source #
Obtain a Fold1
from a Traversable1
functor.
folding1
f ≡traversed1
.to
ffolding1
f ≡fold1Vl
traverse1
.to
f
Cofold1 & Cxfold
type Cofold1 t b = forall p. (Cochoice p, Corepresentable p, Apply (Corep p), Bifunctor p) => Optic p t t b b Source #
cofolding1 :: Distributive f => (b -> t) -> Cofold1 (f t) b Source #
Obtain an Cofold1
from a Distributive
functor.
cofolding1
f ≡cotraversed1
.from
fcofolding1
f ≡cofold1Vl
cotraverse
.from
f
Optics
folded1 :: Traversable1 f => Fold1 (f a) a Source #
Obtain a Fold1
from a Traversable1
functor.
cofolded1 :: Distributive f => Cofold1 (f b) b Source #
Obtain an Cofold1
from a Distributive
functor.
nonunital :: Foldable f => Foldable1 g => Monoid r => Semiring r => AFold r (f (g a)) a Source #
Expression in a semiring expression with no multiplicative unit.
nonunital
≡summed
.multiplied1
>>>
foldOf nonunital $ (fmap . fmap) Just [1 :| [2], 3 :| [4 :: Int]]
Just 14
presemiring :: Foldable1 f => Foldable1 g => Semiring r => AFold1 r (f (g a)) a Source #
Expression in a semiring with no additive or multiplicative unit.
presemiring
≡summed1
.multiplied1
summed1 :: Foldable1 f => Semigroup r => AFold1 r (f a) a Source #
Semigroup sum of a non-empty foldable collection.
>>>
1 <> 2 <> 3 <> 4 :: Int
10>>>
fold1Of summed1 $ 1 :| [2,3,4 :: Int]
10
multiplied1 :: Foldable1 f => Semiring r => AFold1 r (f a) a Source #
Semiring product of a non-empty foldable collection.
>>>
fold1Of multiplied1 $ fmap Just (1 :| [2..(5 :: Int)])
Just 120
Primitive operators
withFold1 :: Semigroup r => AFold1 r s a -> (a -> r) -> s -> r Source #
Map an optic to a semigroup and combine the results.
withCofold1 :: ACofold1 r t b -> (r -> b) -> r -> t Source #
Operators
folds1p :: Semiring r => AFold (Prod r) s a -> (a -> r) -> s -> r Source #
Compute the semiring product of the foci of an optic.
For semirings without a multiplicative unit this is equivalent to const mempty
:
>>>
productOf folded Just [1..(5 :: Int)]
Just 0
In this situation you most likely want to use folds1p
.
Carriers
type Cofold1Rep r = Costar (Const r) Source #
type ACofold1 r t b = Optic' (Cofold1Rep r) t b Source #
newtype Star (f :: Type -> Type) d c #
Lift a Functor
into a Profunctor
(forwards).
Instances
Functor f => Representable (Star f) | |
Applicative f => Choice (Star f) | |
Traversable f => Cochoice (Star f) | |
Distributive f => Closed (Star f) | |
Defined in Data.Profunctor.Closed | |
Functor m => Strong (Star m) | |
Functor f => Profunctor (Star f) | |
Defined in Data.Profunctor.Types | |
Functor f => Sieve (Star f) f | |
Defined in Data.Profunctor.Sieve | |
Monad f => Category (Star f :: Type -> Type -> Type) | |
Monad f => Monad (Star f a) | |
Functor f => Functor (Star f a) | |
Applicative f => Applicative (Star f a) | |
Contravariant f => Contravariant (Star f a) Source # | |
Alternative f => Alternative (Star f a) | |
MonadPlus f => MonadPlus (Star f a) | |
Distributive f => Distributive (Star f a) | |
Defined in Data.Profunctor.Types | |
Apply f => Apply (Star f a) Source # | |
type Rep (Star f) | |
Defined in Data.Profunctor.Rep |
newtype Costar (f :: Type -> Type) d c #
Lift a Functor
into a Profunctor
(backwards).
Instances
Contravariant f => Bifunctor (Costar f) Source # | |
Functor f => Corepresentable (Costar f) | |
Traversable w => Choice (Costar w) | |
Applicative f => Cochoice (Costar f) | |
Functor f => Closed (Costar f) | |
Defined in Data.Profunctor.Closed | |
Comonad f => Strong (Costar f) Source # | |
Functor f => Costrong (Costar f) | |
Functor f => Profunctor (Costar f) | |
Defined in Data.Profunctor.Types | |
Functor f => Cosieve (Costar f) f | |
Defined in Data.Profunctor.Sieve | |
Monad (Costar f a) | |
Functor (Costar f a) | |
Applicative (Costar f a) | |
Defined in Data.Profunctor.Types | |
Distributive (Costar f d) | |
Defined in Data.Profunctor.Types | |
type Corep (Costar f) | |
Defined in Data.Profunctor.Rep |
Classes
class (Sieve p (Rep p), Strong p) => Representable (p :: Type -> Type -> Type) where #
A Profunctor
p
is Representable
if there exists a Functor
f
such that
p d c
is isomorphic to d -> f c
.
Instances
(Monad m, Functor m) => Representable (Kleisli m) | |
Functor f => Representable (Star f) | |
Representable (Forget r) | |
Representable (Fold0Rep r) Source # | |
Representable ((->) :: Type -> Type -> Type) | |
Representable (LensRep a b) Source # | |
Representable (Traversal0Rep a b) Source # | |
Defined in Data.Profunctor.Optic.Traversal0 type Rep (Traversal0Rep a b) :: Type -> Type # tabulate :: (d -> Rep (Traversal0Rep a b) c) -> Traversal0Rep a b d c # |
class (Cosieve p (Corep p), Costrong p) => Corepresentable (p :: Type -> Type -> Type) where #
A Profunctor
p
is Corepresentable
if there exists a Functor
f
such that
p d c
is isomorphic to f d -> c
.
cotabulate :: (Corep p d -> c) -> p d c #
Laws:
cotabulate
.
cosieve
≡id
cosieve
.
cotabulate
≡id
Instances
Functor f => Corepresentable (Costar f) | |
Corepresentable (Tagged :: Type -> Type -> Type) | |
Corepresentable ((->) :: Type -> Type -> Type) | |
Defined in Data.Profunctor.Rep cotabulate :: (Corep (->) d -> c) -> d -> c # | |
Functor w => Corepresentable (Cokleisli w) | |
Corepresentable (GrateRep a b) Source # | |
class Contravariant (f :: Type -> Type) where #
The class of contravariant functors.
Whereas in Haskell, one can think of a Functor
as containing or producing
values, a contravariant functor is a functor that can be thought of as
consuming values.
As an example, consider the type of predicate functions a -> Bool
. One
such predicate might be negative x = x < 0
, which
classifies integers as to whether they are negative. However, given this
predicate, we can re-use it in other situations, providing we have a way to
map values to integers. For instance, we can use the negative
predicate
on a person's bank balance to work out if they are currently overdrawn:
newtype Predicate a = Predicate { getPredicate :: a -> Bool } instance Contravariant Predicate where contramap f (Predicate p) = Predicate (p . f) | `- First, map the input... `----- then apply the predicate. overdrawn :: Predicate Person overdrawn = contramap personBankBalance negative
Any instance should be subject to the following laws:
contramap id = id contramap f . contramap g = contramap (g . f)
Note, that the second law follows from the free theorem of the type of
contramap
and the first law, so you need only check that the former
condition holds.
Instances
class Bifunctor (p :: Type -> Type -> Type) where #
A bifunctor is a type constructor that takes
two type arguments and is a functor in both arguments. That
is, unlike with Functor
, a type constructor such as Either
does not need to be partially applied for a Bifunctor
instance, and the methods in this class permit mapping
functions over the Left
value or the Right
value,
or both at the same time.
Formally, the class Bifunctor
represents a bifunctor
from Hask
-> Hask
.
Intuitively it is a bifunctor where both the first and second arguments are covariant.
You can define a Bifunctor
by either defining bimap
or by
defining both first
and second
.
If you supply bimap
, you should ensure that:
bimap
id
id
≡id
If you supply first
and second
, ensure:
first
id
≡id
second
id
≡id
If you supply both, you should also ensure:
bimap
f g ≡first
f.
second
g
These ensure by parametricity:
bimap
(f.
g) (h.
i) ≡bimap
f h.
bimap
g ifirst
(f.
g) ≡first
f.
first
gsecond
(f.
g) ≡second
f.
second
g
Since: base-4.8.0.0
bimap :: (a -> b) -> (c -> d) -> p a c -> p b d #
Map over both arguments at the same time.
bimap
f g ≡first
f.
second
g
Examples
>>>
bimap toUpper (+1) ('j', 3)
('J',4)
>>>
bimap toUpper (+1) (Left 'j')
Left 'J'
>>>
bimap toUpper (+1) (Right 3)
Right 4