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.
The class definition of a Bifunctor p uses the
QuantifiedConstraints
language extension to quantify over the first type
argument a in its context. The context requires that p a
must be a Functor for all a. In other words a partially
applied Bifunctor must be a Functor. This makes Functor a
superclass of Bifunctor such that a function with a
Bifunctor constraint may use fmap in its implementation.
Functor has been a quantified superclass of
Bifunctor since base-4.18.0.0.
You can define a Bifunctor by either defining bimap or by defining both first and second. The second method must agree with fmap:
second ≡ fmapFrom this it follows that:
second id ≡ idIf you supply bimap, you should ensure that:
bimap id id ≡ idIf 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 gThese ensure by parametricity:
bimap (f . g) (h . i) ≡ bimap f h . bimap g i
first (f . g) ≡ first f . first g
second (f . g) ≡ second f . second g
Methods
Instances21Bifunctor, …
Bifunctor ArgDefined in base-4.20.2.0 · Data.SemigroupBifunctor EitherDefined in base-4.20.2.0 · Data.BifunctorBifunctor Tuple2Defined in base-4.20.2.0 · Data.BifunctorBifunctor ConstDefined in base-4.20.2.0 · Data.BifunctorBifunctor TaggedDefined in tagged-0.8.9 · Data.TaggedBifunctor ConstantDefined in transformers-0.6.1.1 · Data.Functor.ConstantBifunctor (Tuple3 x1)Defined in base-4.20.2.0 · Data.BifunctorBifunctor bi => Bifunctor (Biap bi)Defined in bifunctors-5.6.2 · Data.Bifunctor.BiapBifunctor (K1 i)Defined in base-4.20.2.0 · Data.BifunctorBifunctor (Tuple4 x1 x2)Defined in base-4.20.2.0 · Data.BifunctorBifunctor (Tuple5 x1 x2 x3)Defined in base-4.20.2.0 · Data.BifunctorBifunctor p => Bifunctor (Flip p)Defined in bifunctors-5.6.2 · Data.Bifunctor.FlipBifunctor p => Bifunctor (WrappedBifunctor p)Defined in bifunctors-5.6.2 · Data.Bifunctor.WrappedFunctor f => Bifunctor (Clown f)Defined in bifunctors-5.6.2 · Data.Bifunctor.ClownFunctor g => Bifunctor (Joker g)Defined in bifunctors-5.6.2 · Data.Bifunctor.JokerBifunctor (Tuple6 x1 x2 x3 x4)Defined in base-4.20.2.0 · Data.Bifunctor(Bifunctor f, Bifunctor g) => Bifunctor (Product f g)Defined in bifunctors-5.6.2 · Data.Bifunctor.Product(Bifunctor p, Bifunctor q) => Bifunctor (Sum p q)Defined in bifunctors-5.6.2 · Data.Bifunctor.SumBifunctor (Tuple7 x1 x2 x3 x4 x5)Defined in base-4.20.2.0 · Data.Bifunctor(Functor f, Bifunctor p) => Bifunctor (Tannen f p)Defined in bifunctors-5.6.2 · Data.Bifunctor.Tannen(Bifunctor p, Functor f, Functor g) => Bifunctor (Biff p f g)Defined in bifunctors-5.6.2 · Data.Bifunctor.Biff