planet-mitchell-0.0.0: Planet Mitchell

Safe HaskellSafe
LanguageHaskell2010

Bifunctor

Contents

Synopsis

Bifunctor

class Bifunctor (p :: * -> * -> *) 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 idid

If you supply first and second, ensure:

first idid
second idid

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 i
first  (f . g) ≡ first  f . first  g
second (f . g) ≡ second f . second g

Since: base-4.8.0.0

Minimal complete definition

bimap | first, second

Methods

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

Expand
>>> bimap toUpper (+1) ('j', 3)
('J',4)
>>> bimap toUpper (+1) (Left 'j')
Left 'J'
>>> bimap toUpper (+1) (Right 3)
Right 4

first :: (a -> b) -> p a c -> p b c #

Map covariantly over the first argument.

first f ≡ bimap f id

Examples

Expand
>>> first toUpper ('j', 3)
('J',3)
>>> first toUpper (Left 'j')
Left 'J'

second :: (b -> c) -> p a b -> p a c #

Map covariantly over the second argument.

secondbimap id

Examples

Expand
>>> second (+1) ('j', 3)
('j',4)
>>> second (+1) (Right 3)
Right 4
Instances
Bifunctor Either

Since: base-4.8.0.0

Instance details

Defined in Data.Bifunctor

Methods

bimap :: (a -> b) -> (c -> d) -> Either a c -> Either b d #

first :: (a -> b) -> Either a c -> Either b c #

second :: (b -> c) -> Either a b -> Either a c #

Bifunctor (,)

Since: base-4.8.0.0

Instance details

Defined in Data.Bifunctor

Methods

bimap :: (a -> b) -> (c -> d) -> (a, c) -> (b, d) #

first :: (a -> b) -> (a, c) -> (b, c) #

second :: (b -> c) -> (a, b) -> (a, c) #

Bifunctor Arg

Since: base-4.9.0.0

Instance details

Defined in Data.Semigroup

Methods

bimap :: (a -> b) -> (c -> d) -> Arg a c -> Arg b d #

first :: (a -> b) -> Arg a c -> Arg b c #

second :: (b -> c) -> Arg a b -> Arg a c #

Bifunctor Gr 
Instance details

Defined in Data.Graph.Inductive.PatriciaTree

Methods

bimap :: (a -> b) -> (c -> d) -> Gr a c -> Gr b d #

first :: (a -> b) -> Gr a c -> Gr b c #

second :: (b -> c) -> Gr a b -> Gr a c #

Bifunctor Entry 
Instance details

Defined in Data.Heap

Methods

bimap :: (a -> b) -> (c -> d) -> Entry a c -> Entry b d #

first :: (a -> b) -> Entry a c -> Entry b c #

second :: (b -> c) -> Entry a b -> Entry a c #

Bifunctor ((,,) x1)

Since: base-4.8.0.0

Instance details

Defined in Data.Bifunctor

Methods

bimap :: (a -> b) -> (c -> d) -> (x1, a, c) -> (x1, b, d) #

first :: (a -> b) -> (x1, a, c) -> (x1, b, c) #

second :: (b -> c) -> (x1, a, b) -> (x1, a, c) #

Bifunctor (Const :: * -> * -> *)

Since: base-4.8.0.0

Instance details

Defined in Data.Bifunctor

Methods

bimap :: (a -> b) -> (c -> d) -> Const a c -> Const b d #

first :: (a -> b) -> Const a c -> Const b c #

second :: (b -> c) -> Const a b -> Const a c #

Functor f => Bifunctor (FreeF f) 
Instance details

Defined in Control.Monad.Trans.Free

Methods

bimap :: (a -> b) -> (c -> d) -> FreeF f a c -> FreeF f b d #

first :: (a -> b) -> FreeF f a c -> FreeF f b c #

second :: (b -> c) -> FreeF f a b -> FreeF f a c #

Functor f => Bifunctor (CofreeF f) 
Instance details

Defined in Control.Comonad.Trans.Cofree

Methods

bimap :: (a -> b) -> (c -> d) -> CofreeF f a c -> CofreeF f b d #

first :: (a -> b) -> CofreeF f a c -> CofreeF f b c #

second :: (b -> c) -> CofreeF f a b -> CofreeF f a c #

Bifunctor (Tagged :: * -> * -> *) 
Instance details

Defined in Data.Tagged

Methods

bimap :: (a -> b) -> (c -> d) -> Tagged a c -> Tagged b d #

first :: (a -> b) -> Tagged a c -> Tagged b c #

second :: (b -> c) -> Tagged a b -> Tagged a c #

Bifunctor (K1 i :: * -> * -> *)

Since: base-4.9.0.0

Instance details

Defined in Data.Bifunctor

Methods

bimap :: (a -> b) -> (c -> d) -> K1 i a c -> K1 i b d #

first :: (a -> b) -> K1 i a c -> K1 i b c #

second :: (b -> c) -> K1 i a b -> K1 i a c #

Bifunctor ((,,,) x1 x2)

Since: base-4.8.0.0

Instance details

Defined in Data.Bifunctor

Methods

bimap :: (a -> b) -> (c -> d) -> (x1, x2, a, c) -> (x1, x2, b, d) #

first :: (a -> b) -> (x1, x2, a, c) -> (x1, x2, b, c) #

second :: (b -> c) -> (x1, x2, a, b) -> (x1, x2, a, c) #

Bifunctor ((,,,,) x1 x2 x3)

Since: base-4.8.0.0

Instance details

Defined in Data.Bifunctor

Methods

bimap :: (a -> b) -> (c -> d) -> (x1, x2, x3, a, c) -> (x1, x2, x3, b, d) #

first :: (a -> b) -> (x1, x2, x3, a, c) -> (x1, x2, x3, b, c) #

second :: (b -> c) -> (x1, x2, x3, a, b) -> (x1, x2, x3, a, c) #

Bifunctor p => Bifunctor (WrappedBifunctor p) 
Instance details

Defined in Data.Bifunctor.Wrapped

Methods

bimap :: (a -> b) -> (c -> d) -> WrappedBifunctor p a c -> WrappedBifunctor p b d #

first :: (a -> b) -> WrappedBifunctor p a c -> WrappedBifunctor p b c #

second :: (b -> c) -> WrappedBifunctor p a b -> WrappedBifunctor p a c #

Functor g => Bifunctor (Joker g :: * -> * -> *) 
Instance details

Defined in Data.Bifunctor.Joker

Methods

bimap :: (a -> b) -> (c -> d) -> Joker g a c -> Joker g b d #

first :: (a -> b) -> Joker g a c -> Joker g b c #

second :: (b -> c) -> Joker g a b -> Joker g a c #

Bifunctor p => Bifunctor (Flip p) 
Instance details

Defined in Data.Bifunctor.Flip

Methods

bimap :: (a -> b) -> (c -> d) -> Flip p a c -> Flip p b d #

first :: (a -> b) -> Flip p a c -> Flip p b c #

second :: (b -> c) -> Flip p a b -> Flip p a c #

Functor f => Bifunctor (Clown f :: * -> * -> *) 
Instance details

Defined in Data.Bifunctor.Clown

Methods

bimap :: (a -> b) -> (c -> d) -> Clown f a c -> Clown f b d #

first :: (a -> b) -> Clown f a c -> Clown f b c #

second :: (b -> c) -> Clown f a b -> Clown f a c #

Bifunctor ((,,,,,) x1 x2 x3 x4)

Since: base-4.8.0.0

Instance details

Defined in Data.Bifunctor

Methods

bimap :: (a -> b) -> (c -> d) -> (x1, x2, x3, x4, a, c) -> (x1, x2, x3, x4, b, d) #

first :: (a -> b) -> (x1, x2, x3, x4, a, c) -> (x1, x2, x3, x4, b, c) #

second :: (b -> c) -> (x1, x2, x3, x4, a, b) -> (x1, x2, x3, x4, a, c) #

(Bifunctor p, Bifunctor q) => Bifunctor (Sum p q) 
Instance details

Defined in Data.Bifunctor.Sum

Methods

bimap :: (a -> b) -> (c -> d) -> Sum p q a c -> Sum p q b d #

first :: (a -> b) -> Sum p q a c -> Sum p q b c #

second :: (b -> c) -> Sum p q a b -> Sum p q a c #

(Bifunctor f, Bifunctor g) => Bifunctor (Product f g) 
Instance details

Defined in Data.Bifunctor.Product

Methods

bimap :: (a -> b) -> (c -> d) -> Product f g a c -> Product f g b d #

first :: (a -> b) -> Product f g a c -> Product f g b c #

second :: (b -> c) -> Product f g a b -> Product f g a c #

Bifunctor ((,,,,,,) x1 x2 x3 x4 x5)

Since: base-4.8.0.0

Instance details

Defined in Data.Bifunctor

Methods

bimap :: (a -> b) -> (c -> d) -> (x1, x2, x3, x4, x5, a, c) -> (x1, x2, x3, x4, x5, b, d) #

first :: (a -> b) -> (x1, x2, x3, x4, x5, a, c) -> (x1, x2, x3, x4, x5, b, c) #

second :: (b -> c) -> (x1, x2, x3, x4, x5, a, b) -> (x1, x2, x3, x4, x5, a, c) #

(Functor f, Bifunctor p) => Bifunctor (Tannen f p) 
Instance details

Defined in Data.Bifunctor.Tannen

Methods

bimap :: (a -> b) -> (c -> d) -> Tannen f p a c -> Tannen f p b d #

first :: (a -> b) -> Tannen f p a c -> Tannen f p b c #

second :: (b -> c) -> Tannen f p a b -> Tannen f p a c #

(Bifunctor p, Functor f, Functor g) => Bifunctor (Biff p f g) 
Instance details

Defined in Data.Bifunctor.Biff

Methods

bimap :: (a -> b) -> (c -> d) -> Biff p f g a c -> Biff p f g b d #

first :: (a -> b) -> Biff p f g a c -> Biff p f g b c #

second :: (b -> c) -> Biff p f g a b -> Biff p f g a c #

class Bifunctor p => Swapped (p :: * -> * -> *) where #

This class provides for symmetric bifunctors.

Minimal complete definition

swapped

Methods

swapped :: (Profunctor p, Functor f) => p (p b a) (f (p d c)) -> p (p a b) (f (p c d)) #

swapped . swappedid
first f . swapped = swapped . second f
second g . swapped = swapped . first g
bimap f g . swapped = swapped . bimap g f
>>> (1,2)^.swapped
(2,1)
Instances
Swapped Either 
Instance details

Defined in Control.Lens.Iso

Methods

swapped :: (Profunctor p, Functor f) => p (Either b a) (f (Either d c)) -> p (Either a b) (f (Either c d)) #

Swapped (,) 
Instance details

Defined in Control.Lens.Iso

Methods

swapped :: (Profunctor p, Functor f) => p (b, a) (f (d, c)) -> p (a, b) (f (c, d)) #

Biapply

class Bifunctor p => Biapply (p :: * -> * -> *) where #

Minimal complete definition

(<<.>>)

Methods

(<<.>>) :: p (a -> b) (c -> d) -> p a c -> p b d infixl 4 #

(.>>) :: p a b -> p c d -> p c d infixl 4 #

a .> b ≡ const id <$> a <.> b

(<<.) :: p a b -> p c d -> p a b infixl 4 #

a <. b ≡ const <$> a <.> b
Instances
Biapply (,) 
Instance details

Defined in Data.Functor.Bind.Class

Methods

(<<.>>) :: (a -> b, c -> d) -> (a, c) -> (b, d) #

(.>>) :: (a, b) -> (c, d) -> (c, d) #

(<<.) :: (a, b) -> (c, d) -> (a, b) #

Biapply Arg 
Instance details

Defined in Data.Functor.Bind.Class

Methods

(<<.>>) :: Arg (a -> b) (c -> d) -> Arg a c -> Arg b d #

(.>>) :: Arg a b -> Arg c d -> Arg c d #

(<<.) :: Arg a b -> Arg c d -> Arg a b #

Semigroup x => Biapply ((,,) x) 
Instance details

Defined in Data.Functor.Bind.Class

Methods

(<<.>>) :: (x, a -> b, c -> d) -> (x, a, c) -> (x, b, d) #

(.>>) :: (x, a, b) -> (x, c, d) -> (x, c, d) #

(<<.) :: (x, a, b) -> (x, c, d) -> (x, a, b) #

Biapply (Const :: * -> * -> *) 
Instance details

Defined in Data.Functor.Bind.Class

Methods

(<<.>>) :: Const (a -> b) (c -> d) -> Const a c -> Const b d #

(.>>) :: Const a b -> Const c d -> Const c d #

(<<.) :: Const a b -> Const c d -> Const a b #

Biapply (Tagged :: * -> * -> *) 
Instance details

Defined in Data.Functor.Bind.Class

Methods

(<<.>>) :: Tagged (a -> b) (c -> d) -> Tagged a c -> Tagged b d #

(.>>) :: Tagged a b -> Tagged c d -> Tagged c d #

(<<.) :: Tagged a b -> Tagged c d -> Tagged a b #

(Semigroup x, Semigroup y) => Biapply ((,,,) x y) 
Instance details

Defined in Data.Functor.Bind.Class

Methods

(<<.>>) :: (x, y, a -> b, c -> d) -> (x, y, a, c) -> (x, y, b, d) #

(.>>) :: (x, y, a, b) -> (x, y, c, d) -> (x, y, c, d) #

(<<.) :: (x, y, a, b) -> (x, y, c, d) -> (x, y, a, b) #

(Semigroup x, Semigroup y, Semigroup z) => Biapply ((,,,,) x y z) 
Instance details

Defined in Data.Functor.Bind.Class

Methods

(<<.>>) :: (x, y, z, a -> b, c -> d) -> (x, y, z, a, c) -> (x, y, z, b, d) #

(.>>) :: (x, y, z, a, b) -> (x, y, z, c, d) -> (x, y, z, c, d) #

(<<.) :: (x, y, z, a, b) -> (x, y, z, c, d) -> (x, y, z, a, b) #

Biapply p => Biapply (WrappedBifunctor p) 
Instance details

Defined in Data.Functor.Bind.Class

Methods

(<<.>>) :: WrappedBifunctor p (a -> b) (c -> d) -> WrappedBifunctor p a c -> WrappedBifunctor p b d #

(.>>) :: WrappedBifunctor p a b -> WrappedBifunctor p c d -> WrappedBifunctor p c d #

(<<.) :: WrappedBifunctor p a b -> WrappedBifunctor p c d -> WrappedBifunctor p a b #

Apply g => Biapply (Joker g :: * -> * -> *) 
Instance details

Defined in Data.Functor.Bind.Class

Methods

(<<.>>) :: Joker g (a -> b) (c -> d) -> Joker g a c -> Joker g b d #

(.>>) :: Joker g a b -> Joker g c d -> Joker g c d #

(<<.) :: Joker g a b -> Joker g c d -> Joker g a b #

Biapply p => Biapply (Flip p) 
Instance details

Defined in Data.Functor.Bind.Class

Methods

(<<.>>) :: Flip p (a -> b) (c -> d) -> Flip p a c -> Flip p b d #

(.>>) :: Flip p a b -> Flip p c d -> Flip p c d #

(<<.) :: Flip p a b -> Flip p c d -> Flip p a b #

Apply f => Biapply (Clown f :: * -> * -> *) 
Instance details

Defined in Data.Functor.Bind.Class

Methods

(<<.>>) :: Clown f (a -> b) (c -> d) -> Clown f a c -> Clown f b d #

(.>>) :: Clown f a b -> Clown f c d -> Clown f c d #

(<<.) :: Clown f a b -> Clown f c d -> Clown f a b #

(Biapply p, Biapply q) => Biapply (Product p q) 
Instance details

Defined in Data.Functor.Bind.Class

Methods

(<<.>>) :: Product p q (a -> b) (c -> d) -> Product p q a c -> Product p q b d #

(.>>) :: Product p q a b -> Product p q c d -> Product p q c d #

(<<.) :: Product p q a b -> Product p q c d -> Product p q a b #

(Apply f, Biapply p) => Biapply (Tannen f p) 
Instance details

Defined in Data.Functor.Bind.Class

Methods

(<<.>>) :: Tannen f p (a -> b) (c -> d) -> Tannen f p a c -> Tannen f p b d #

(.>>) :: Tannen f p a b -> Tannen f p c d -> Tannen f p c d #

(<<.) :: Tannen f p a b -> Tannen f p c d -> Tannen f p a b #

(Biapply p, Apply f, Apply g) => Biapply (Biff p f g) 
Instance details

Defined in Data.Functor.Bind.Class

Methods

(<<.>>) :: Biff p f g (a -> b) (c -> d) -> Biff p f g a c -> Biff p f g b d #

(.>>) :: Biff p f g a b -> Biff p f g c d -> Biff p f g c d #

(<<.) :: Biff p f g a b -> Biff p f g c d -> Biff p f g a b #