semigroupoids-6.0.1: Semigroupoids: Category sans id

Copyright | (C) 2011-2015 Edward Kmett
License | BSD-style (see the file LICENSE)
Maintainer | Edward Kmett <ekmett@gmail.com>
Stability | provisional
Portability | portable
Safe Haskell | Safe
Language | Haskell2010

Data.Bifunctor.Apply

Contents

- Biappliable bifunctors

Description

Synopsis

- class (forall a. Functor (p a)) => Bifunctor (p :: Type -> Type -> Type) where
  - bimap :: (a -> b) -> (c -> d) -> p a c -> p b d
  - first :: (a -> b) -> p a c -> p b c
  - second :: (b -> c) -> p a b -> p a c
- class Bifunctor p => Biapply (p :: Type -> Type -> Type) where
  - (<<.>>) :: p (a -> b) (c -> d) -> p a c -> p b d
  - (.>>) :: p a b -> p c d -> p c d
  - (<<.) :: p a b -> p c d -> p a b
- (<<$>>) :: (a -> b) -> a -> b
- (<<..>>) :: Biapply p => p a c -> p (a -> b) (c -> d) -> p b d
- bilift2 :: Biapply w => (a -> b -> c) -> (d -> e -> f) -> w a d -> w b e -> w c f
- bilift3 :: Biapply w => (a -> b -> c -> d) -> (e -> f -> g -> h) -> w a e -> w b f -> w c g -> w d h

# Biappliable bifunctors

class (forall a. Functor (p a)) => Bifunctor (p :: Type -> Type -> Type) where Source #

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 ≡ fmap

From this it follows that:

    second id ≡ id

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 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 Source #

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 Source #

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 Source #

Map covariantly over the second argument.

    second ≡ bimap id

#### Examples

Expand

    >>> second (+1) ('j', 3)
    ('j',4)

    >>> second (+1) (Right 3)
    Right 4

#### Instances

Instances details

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 Source # first :: (a -> b) -> Arg a c -> Arg b c Source # second :: (b -> c) -> Arg a b -> Arg a c Source #
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 Source # first :: (a -> b) -> Either a c -> Either b c Source # second :: (b -> c) -> Either a b -> Either a c Source #

Bifunctor (,)

Class laws for tuples hold only up to laziness. Both `first` `id` and `second` `id` are lazier than `id` (and `fmap` `id`):

    >>> first id (undefined :: (Int, Word)) `seq` ()
    ()
    >>> second id (undefined :: (Int, Word)) `seq` ()
    ()
    >>> id (undefined :: (Int, Word)) `seq` ()
    *** Exception: Prelude.undefined

Since: base-4.8.0.0

Instance details Defined in Data.Bifunctor Methods bimap :: (a -> b) -> (c -> d) -> (a, c) -> (b, d) Source # first :: (a -> b) -> (a, c) -> (b, c) Source # second :: (b -> c) -> (a, b) -> (a, c) Source #
Bifunctor bi => Bifunctor (Biap bi) |
Instance details Defined in Data.Bifunctor.Biap Methods bimap :: (a -> b) -> (c -> d) -> Biap bi a c -> Biap bi b d Source # first :: (a -> b) -> Biap bi a c -> Biap bi b c Source # second :: (b -> c) -> Biap bi a b -> Biap bi a c Source #
Bifunctor (Const :: Type -> Type -> Type) | Since: base-4.8.0.0
Instance details Defined in Data.Bifunctor Methods bimap :: (a -> b) -> (c -> d) -> Const a c -> Const b d Source # first :: (a -> b) -> Const a c -> Const b c Source # second :: (b -> c) -> Const a b -> Const a c Source #
Bifunctor (Tagged :: Type -> Type -> Type) |
Instance details Defined in Data.Tagged Methods bimap :: (a -> b) -> (c -> d) -> Tagged a c -> Tagged b d Source # first :: (a -> b) -> Tagged a c -> Tagged b c Source # second :: (b -> c) -> Tagged a b -> Tagged a c Source #
Bifunctor (Constant :: Type -> Type -> Type) |
Instance details Defined in Data.Functor.Constant Methods bimap :: (a -> b) -> (c -> d) -> Constant a c -> Constant b d Source # first :: (a -> b) -> Constant a c -> Constant b c Source # second :: (b -> c) -> Constant a b -> Constant a c Source #
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) Source # first :: (a -> b) -> (x1, a, c) -> (x1, b, c) Source # second :: (b -> c) -> (x1, a, b) -> (x1, a, c) Source #
Bifunctor (K1 i :: Type -> Type -> Type) | 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 Source # first :: (a -> b) -> K1 i a c -> K1 i b c Source # second :: (b -> c) -> K1 i a b -> K1 i a c Source #
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) Source # first :: (a -> b) -> (x1, x2, a, c) -> (x1, x2, b, c) Source # second :: (b -> c) -> (x1, x2, a, b) -> (x1, x2, a, c) Source #
Functor f => Bifunctor (Clown f :: Type -> Type -> Type) |
Instance details Defined in Data.Bifunctor.Clown Methods bimap :: (a -> b) -> (c -> d) -> Clown f a c -> Clown f b d Source # first :: (a -> b) -> Clown f a c -> Clown f b c Source # second :: (b -> c) -> Clown f a b -> Clown f a c Source #
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 Source # first :: (a -> b) -> Flip p a c -> Flip p b c Source # second :: (b -> c) -> Flip p a b -> Flip p a c Source #
Functor g => Bifunctor (Joker g :: Type -> Type -> Type) |
Instance details Defined in Data.Bifunctor.Joker Methods bimap :: (a -> b) -> (c -> d) -> Joker g a c -> Joker g b d Source # first :: (a -> b) -> Joker g a c -> Joker g b c Source # second :: (b -> c) -> Joker g a b -> Joker g a c Source #
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 Source # first :: (a -> b) -> WrappedBifunctor p a c -> WrappedBifunctor p b c Source # second :: (b -> c) -> WrappedBifunctor p a b -> WrappedBifunctor p a c Source #
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) Source # first :: (a -> b) -> (x1, x2, x3, a, c) -> (x1, x2, x3, b, c) Source # second :: (b -> c) -> (x1, x2, x3, a, b) -> (x1, x2, x3, a, c) Source #
(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 Source # first :: (a -> b) -> Product f g a c -> Product f g b c Source # second :: (b -> c) -> Product f g a b -> Product f g a c Source #
(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 Source # first :: (a -> b) -> Sum p q a c -> Sum p q b c Source # second :: (b -> c) -> Sum p q a b -> Sum p q a c Source #
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) Source # first :: (a -> b) -> (x1, x2, x3, x4, a, c) -> (x1, x2, x3, x4, b, c) Source # second :: (b -> c) -> (x1, x2, x3, x4, a, b) -> (x1, x2, x3, x4, a, c) Source #
(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 Source # first :: (a -> b) -> Tannen f p a c -> Tannen f p b c Source # second :: (b -> c) -> Tannen f p a b -> Tannen f p a c Source #
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) Source # first :: (a -> b) -> (x1, x2, x3, x4, x5, a, c) -> (x1, x2, x3, x4, x5, b, c) Source # second :: (b -> c) -> (x1, x2, x3, x4, x5, a, b) -> (x1, x2, x3, x4, x5, a, c) Source #
(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 Source # first :: (a -> b) -> Biff p f g a c -> Biff p f g b c Source # second :: (b -> c) -> Biff p f g a b -> Biff p f g a c Source #

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

Minimal complete definition

(<<.>>)

Methods

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

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

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

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

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

#### Instances

Instances details

Biapply Arg Source # |
Instance details Defined in Data.Functor.Bind.Class Methods (<<.>>) :: Arg (a -> b) (c -> d) -> Arg a c -> Arg b d Source # (.>>) :: Arg a b -> Arg c d -> Arg c d Source # (<<.) :: Arg a b -> Arg c d -> Arg a b Source #
Biapply (,) Source # |
Instance details Defined in Data.Functor.Bind.Class Methods (<<.>>) :: (a -> b, c -> d) -> (a, c) -> (b, d) Source # (.>>) :: (a, b) -> (c, d) -> (c, d) Source # (<<.) :: (a, b) -> (c, d) -> (a, b) Source #
Biapply (Const :: Type -> Type -> Type) Source # |
Instance details Defined in Data.Functor.Bind.Class Methods (<<.>>) :: Const (a -> b) (c -> d) -> Const a c -> Const b d Source # (.>>) :: Const a b -> Const c d -> Const c d Source # (<<.) :: Const a b -> Const c d -> Const a b Source #
Biapply (Tagged :: Type -> Type -> Type) Source # |
Instance details Defined in Data.Functor.Bind.Class Methods (<<.>>) :: Tagged (a -> b) (c -> d) -> Tagged a c -> Tagged b d Source # (.>>) :: Tagged a b -> Tagged c d -> Tagged c d Source # (<<.) :: Tagged a b -> Tagged c d -> Tagged a b Source #
Semigroup x => Biapply ((,,) x) Source # |
Instance details Defined in Data.Functor.Bind.Class Methods (<<.>>) :: (x, a -> b, c -> d) -> (x, a, c) -> (x, b, d) Source # (.>>) :: (x, a, b) -> (x, c, d) -> (x, c, d) Source # (<<.) :: (x, a, b) -> (x, c, d) -> (x, a, b) Source #
(Semigroup x, Semigroup y) => Biapply ((,,,) x y) Source # |
Instance details Defined in Data.Functor.Bind.Class Methods (<<.>>) :: (x, y, a -> b, c -> d) -> (x, y, a, c) -> (x, y, b, d) Source # (.>>) :: (x, y, a, b) -> (x, y, c, d) -> (x, y, c, d) Source # (<<.) :: (x, y, a, b) -> (x, y, c, d) -> (x, y, a, b) Source #
Apply f => Biapply (Clown f :: Type -> Type -> Type) Source # |
Instance details Defined in Data.Functor.Bind.Class Methods (<<.>>) :: Clown f (a -> b) (c -> d) -> Clown f a c -> Clown f b d Source # (.>>) :: Clown f a b -> Clown f c d -> Clown f c d Source # (<<.) :: Clown f a b -> Clown f c d -> Clown f a b Source #
Biapply p => Biapply (Flip p) Source # |
Instance details Defined in Data.Functor.Bind.Class Methods (<<.>>) :: Flip p (a -> b) (c -> d) -> Flip p a c -> Flip p b d Source # (.>>) :: Flip p a b -> Flip p c d -> Flip p c d Source # (<<.) :: Flip p a b -> Flip p c d -> Flip p a b Source #
Apply g => Biapply (Joker g :: Type -> Type -> Type) Source # |
Instance details Defined in Data.Functor.Bind.Class Methods (<<.>>) :: Joker g (a -> b) (c -> d) -> Joker g a c -> Joker g b d Source # (.>>) :: Joker g a b -> Joker g c d -> Joker g c d Source # (<<.) :: Joker g a b -> Joker g c d -> Joker g a b Source #
Biapply p => Biapply (WrappedBifunctor p) Source # |
Instance details Defined in Data.Functor.Bind.Class Methods (<<.>>) :: WrappedBifunctor p (a -> b) (c -> d) -> WrappedBifunctor p a c -> WrappedBifunctor p b d Source # (.>>) :: WrappedBifunctor p a b -> WrappedBifunctor p c d -> WrappedBifunctor p c d Source # (<<.) :: WrappedBifunctor p a b -> WrappedBifunctor p c d -> WrappedBifunctor p a b Source #
(Semigroup x, Semigroup y, Semigroup z) => Biapply ((,,,,) x y z) Source # |
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) Source # (.>>) :: (x, y, z, a, b) -> (x, y, z, c, d) -> (x, y, z, c, d) Source # (<<.) :: (x, y, z, a, b) -> (x, y, z, c, d) -> (x, y, z, a, b) Source #
(Biapply p, Biapply q) => Biapply (Product p q) Source # |
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 Source # (.>>) :: Product p q a b -> Product p q c d -> Product p q c d Source # (<<.) :: Product p q a b -> Product p q c d -> Product p q a b Source #
(Apply f, Biapply p) => Biapply (Tannen f p) Source # |
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 Source # (.>>) :: Tannen f p a b -> Tannen f p c d -> Tannen f p c d Source # (<<.) :: Tannen f p a b -> Tannen f p c d -> Tannen f p a b Source #
(Biapply p, Apply f, Apply g) => Biapply (Biff p f g) Source # |
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 Source # (.>>) :: Biff p f g a b -> Biff p f g c d -> Biff p f g c d Source # (<<.) :: Biff p f g a b -> Biff p f g c d -> Biff p f g a b Source #

(<<$>>) :: (a -> b) -> a -> b infixl 4 Source #

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

bilift2 :: Biapply w => (a -> b -> c) -> (d -> e -> f) -> w a d -> w b e -> w c f Source #

Lift binary functions

bilift3 :: Biapply w => (a -> b -> c -> d) -> (e -> f -> g -> h) -> w a e -> w b f -> w c g -> w d h Source #

Lift ternary functions