Data.Biapplicative

bifunctors-5.5.14: Bifunctors

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 | Trustworthy
Language | Haskell2010

Data.Biapplicative

Contents

- Biapplicative bifunctors

Description

Synopsis

- class Bifunctor p => Biapplicative p where
  - bipure :: a -> b -> p a b
  - (<<*>>) :: p (a -> b) (c -> d) -> p a c -> p b d
  - biliftA2 :: (a -> b -> c) -> (d -> e -> f) -> p a d -> p b e -> p c f
  - (*>>) :: p a b -> p c d -> p c d
  - (<<*) :: p a b -> p c d -> p a b
- (<<$>>) :: (a -> b) -> a -> b
- (<<**>>) :: Biapplicative p => p a c -> p (a -> b) (c -> d) -> p b d
- biliftA3 :: Biapplicative w => (a -> b -> c -> d) -> (e -> f -> g -> h) -> w a e -> w b f -> w c g -> w d h
- traverseBia :: (Traversable t, Biapplicative p) => (a -> p b c) -> t a -> p (t b) (t c)
- sequenceBia :: (Traversable t, Biapplicative p) => t (p b c) -> p (t b) (t c)
- traverseBiaWith :: forall p a b c s t. Biapplicative p => (forall f x. Applicative f => (a -> f x) -> s -> f (t x)) -> (a -> p b c) -> s -> p (t b) (t c)

# Biapplicative bifunctors

class Bifunctor p => Biapplicative p where #

Minimal complete definition

bipure, ((<<*>>) | biliftA2)

Methods

bipure :: a -> b -> p a b #

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

biliftA2 :: (a -> b -> c) -> (d -> e -> f) -> p a d -> p b e -> p c f #

Lift binary functions

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

    a *>> b ≡ bimap (const id) (const id) <<$>> a <<*>> b

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

    a <<* b ≡ bimap const const <<$>> a <<*>> b

#### Instances

Instances details

Biapplicative Arg # |
Instance details Defined in Data.Biapplicative Methods bipure :: a -> b -> Arg a b # (<<*>>) :: Arg (a -> b) (c -> d) -> Arg a c -> Arg b d # biliftA2 :: (a -> b -> c) -> (d -> e -> f) -> Arg a d -> Arg b e -> Arg c f # (*>>) :: Arg a b -> Arg c d -> Arg c d # (<<*) :: Arg a b -> Arg c d -> Arg a b #
Biapplicative (,) # |
Instance details Defined in Data.Biapplicative Methods bipure :: a -> b -> (a, b) # (<<*>>) :: (a -> b, c -> d) -> (a, c) -> (b, d) # biliftA2 :: (a -> b -> c) -> (d -> e -> f) -> (a, d) -> (b, e) -> (c, f) # (*>>) :: (a, b) -> (c, d) -> (c, d) # (<<*) :: (a, b) -> (c, d) -> (a, b) #
Biapplicative (Const :: Type -> Type -> Type) # |
Instance details Defined in Data.Biapplicative Methods bipure :: a -> b -> Const a b # (<<*>>) :: Const (a -> b) (c -> d) -> Const a c -> Const b d # biliftA2 :: (a -> b -> c) -> (d -> e -> f) -> Const a d -> Const b e -> Const c f # (*>>) :: Const a b -> Const c d -> Const c d # (<<*) :: Const a b -> Const c d -> Const a b #
Biapplicative bi => Biapplicative (Biap bi) # |
Instance details Defined in Data.Bifunctor.Biap Methods bipure :: a -> b -> Biap bi a b # (<<*>>) :: Biap bi (a -> b) (c -> d) -> Biap bi a c -> Biap bi b d # biliftA2 :: (a -> b -> c) -> (d -> e -> f) -> Biap bi a d -> Biap bi b e -> Biap bi c f # (*>>) :: Biap bi a b -> Biap bi c d -> Biap bi c d # (<<*) :: Biap bi a b -> Biap bi c d -> Biap bi a b #
Biapplicative (Tagged :: Type -> Type -> Type) # |
Instance details Defined in Data.Biapplicative Methods bipure :: a -> b -> Tagged a b # (<<*>>) :: Tagged (a -> b) (c -> d) -> Tagged a c -> Tagged b d # biliftA2 :: (a -> b -> c) -> (d -> e -> f) -> Tagged a d -> Tagged b e -> Tagged c f # (*>>) :: Tagged a b -> Tagged c d -> Tagged c d # (<<*) :: Tagged a b -> Tagged c d -> Tagged a b #
Monoid x => Biapplicative ((,,) x) # |
Instance details Defined in Data.Biapplicative Methods bipure :: a -> b -> (x, a, b) # (<<*>>) :: (x, a -> b, c -> d) -> (x, a, c) -> (x, b, d) # biliftA2 :: (a -> b -> c) -> (d -> e -> f) -> (x, a, d) -> (x, b, e) -> (x, c, f) # (*>>) :: (x, a, b) -> (x, c, d) -> (x, c, d) # (<<*) :: (x, a, b) -> (x, c, d) -> (x, a, b) #
(Monoid x, Monoid y) => Biapplicative ((,,,) x y) # |
Instance details Defined in Data.Biapplicative Methods bipure :: a -> b -> (x, y, a, b) # (<<*>>) :: (x, y, a -> b, c -> d) -> (x, y, a, c) -> (x, y, b, d) # biliftA2 :: (a -> b -> c) -> (d -> e -> f) -> (x, y, a, d) -> (x, y, b, e) -> (x, y, c, f) # (*>>) :: (x, y, a, b) -> (x, y, c, d) -> (x, y, c, d) # (<<*) :: (x, y, a, b) -> (x, y, c, d) -> (x, y, a, b) #
Applicative f => Biapplicative (Clown f :: Type -> Type -> Type) # |
Instance details Defined in Data.Bifunctor.Clown Methods bipure :: a -> b -> Clown f a b # (<<*>>) :: Clown f (a -> b) (c -> d) -> Clown f a c -> Clown f b d # biliftA2 :: (a -> b -> c) -> (d -> e -> f0) -> Clown f a d -> Clown f b e -> Clown f c f0 # (*>>) :: Clown f a b -> Clown f c d -> Clown f c d # (<<*) :: Clown f a b -> Clown f c d -> Clown f a b #
Biapplicative p => Biapplicative (Flip p) # |
Instance details Defined in Data.Bifunctor.Flip Methods bipure :: a -> b -> Flip p a b # (<<*>>) :: Flip p (a -> b) (c -> d) -> Flip p a c -> Flip p b d # biliftA2 :: (a -> b -> c) -> (d -> e -> f) -> Flip p a d -> Flip p b e -> Flip p c f # (*>>) :: Flip p a b -> Flip p c d -> Flip p c d # (<<*) :: Flip p a b -> Flip p c d -> Flip p a b #
Applicative g => Biapplicative (Joker g :: Type -> Type -> Type) # |
Instance details Defined in Data.Bifunctor.Joker Methods bipure :: a -> b -> Joker g a b # (<<*>>) :: Joker g (a -> b) (c -> d) -> Joker g a c -> Joker g b d # biliftA2 :: (a -> b -> c) -> (d -> e -> f) -> Joker g a d -> Joker g b e -> Joker g c f # (*>>) :: Joker g a b -> Joker g c d -> Joker g c d # (<<*) :: Joker g a b -> Joker g c d -> Joker g a b #
Biapplicative p => Biapplicative (WrappedBifunctor p) # |
Instance details Defined in Data.Bifunctor.Wrapped Methods bipure :: a -> b -> WrappedBifunctor p a b # (<<*>>) :: WrappedBifunctor p (a -> b) (c -> d) -> WrappedBifunctor p a c -> WrappedBifunctor p b d # biliftA2 :: (a -> b -> c) -> (d -> e -> f) -> WrappedBifunctor p a d -> WrappedBifunctor p b e -> WrappedBifunctor p c f # (*>>) :: WrappedBifunctor p a b -> WrappedBifunctor p c d -> WrappedBifunctor p c d # (<<*) :: WrappedBifunctor p a b -> WrappedBifunctor p c d -> WrappedBifunctor p a b #
(Monoid x, Monoid y, Monoid z) => Biapplicative ((,,,,) x y z) # |
Instance details Defined in Data.Biapplicative Methods bipure :: a -> b -> (x, y, z, a, b) # (<<*>>) :: (x, y, z, a -> b, c -> d) -> (x, y, z, a, c) -> (x, y, z, b, d) # biliftA2 :: (a -> b -> c) -> (d -> e -> f) -> (x, y, z, a, d) -> (x, y, z, b, e) -> (x, y, z, c, f) # (*>>) :: (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) #
(Biapplicative f, Biapplicative g) => Biapplicative (Product f g) # |
Instance details Defined in Data.Bifunctor.Product Methods bipure :: a -> b -> Product f g a b # (<<*>>) :: Product f g (a -> b) (c -> d) -> Product f g a c -> Product f g b d # biliftA2 :: (a -> b -> c) -> (d -> e -> f0) -> Product f g a d -> Product f g b e -> Product f g c f0 # (*>>) :: Product f g a b -> Product f g c d -> Product f g c d # (<<*) :: Product f g a b -> Product f g c d -> Product f g a b #
(Monoid x, Monoid y, Monoid z, Monoid w) => Biapplicative ((,,,,,) x y z w) # |
Instance details Defined in Data.Biapplicative Methods bipure :: a -> b -> (x, y, z, w, a, b) # (<<*>>) :: (x, y, z, w, a -> b, c -> d) -> (x, y, z, w, a, c) -> (x, y, z, w, b, d) # biliftA2 :: (a -> b -> c) -> (d -> e -> f) -> (x, y, z, w, a, d) -> (x, y, z, w, b, e) -> (x, y, z, w, c, f) # (*>>) :: (x, y, z, w, a, b) -> (x, y, z, w, c, d) -> (x, y, z, w, c, d) # (<<*) :: (x, y, z, w, a, b) -> (x, y, z, w, c, d) -> (x, y, z, w, a, b) #
(Applicative f, Biapplicative p) => Biapplicative (Tannen f p) # |
Instance details Defined in Data.Bifunctor.Tannen Methods bipure :: a -> b -> Tannen f p a b # (<<*>>) :: Tannen f p (a -> b) (c -> d) -> Tannen f p a c -> Tannen f p b d # biliftA2 :: (a -> b -> c) -> (d -> e -> f0) -> Tannen f p a d -> Tannen f p b e -> Tannen f p c f0 # (*>>) :: 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 #
(Monoid x, Monoid y, Monoid z, Monoid w, Monoid v) => Biapplicative ((,,,,,,) x y z w v) # |
Instance details Defined in Data.Biapplicative Methods bipure :: a -> b -> (x, y, z, w, v, a, b) # (<<*>>) :: (x, y, z, w, v, a -> b, c -> d) -> (x, y, z, w, v, a, c) -> (x, y, z, w, v, b, d) # biliftA2 :: (a -> b -> c) -> (d -> e -> f) -> (x, y, z, w, v, a, d) -> (x, y, z, w, v, b, e) -> (x, y, z, w, v, c, f) # (*>>) :: (x, y, z, w, v, a, b) -> (x, y, z, w, v, c, d) -> (x, y, z, w, v, c, d) # (<<*) :: (x, y, z, w, v, a, b) -> (x, y, z, w, v, c, d) -> (x, y, z, w, v, a, b) #
(Biapplicative p, Applicative f, Applicative g) => Biapplicative (Biff p f g) # |
Instance details Defined in Data.Bifunctor.Biff Methods bipure :: a -> b -> Biff p f g a b # (<<*>>) :: Biff p f g (a -> b) (c -> d) -> Biff p f g a c -> Biff p f g b d # biliftA2 :: (a -> b -> c) -> (d -> e -> f0) -> Biff p f g a d -> Biff p f g b e -> Biff p f g c f0 # (*>>) :: 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 #

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

(<<**>>) :: Biapplicative p => p a c -> p (a -> b) (c -> d) -> p b d infixl 4 #

biliftA3 :: Biapplicative w => (a -> b -> c -> d) -> (e -> f -> g -> h) -> w a e -> w b f -> w c g -> w d h #

Lift ternary functions

traverseBia :: (Traversable t, Biapplicative p) => (a -> p b c) -> t a -> p (t b) (t c) #

Traverse a `Traversable` container in a `Biapplicative`.

`traverseBia` satisfies the following properties:

Pairing

      traverseBia (,) t = (t, t)

Composition

      traverseBia (Biff . bimap g h . f) = Biff . bimap (traverse g) (traverse h) . traverseBia f

      traverseBia (Tannen . fmap f . g) = Tannen . fmap (traverseBia f) . traverse g

Naturality

       t . traverseBia f = traverseBia (t . f)

  for every biapplicative transformation `t`.

  A biapplicative transformation from a `Biapplicative` `P` to a `Biapplicative` `Q` is a function

      t :: P a b -> Q a b

  preserving the `Biapplicative` operations. That is,

  -     t (bipure x y) = bipure x y

  -     t (x <<*>> y) = t x <<*>> t y

### Performance note

`traverseBia` is fairly efficient, and uses compiler rewrite rules to be even more efficient for a few important types like `[]`. However, if performance is critical, you might consider writing a container-specific implementation.

sequenceBia :: (Traversable t, Biapplicative p) => t (p b c) -> p (t b) (t c) #

Perform all the `Biappicative` actions in a `Traversable` container and produce a container with all the results.

    sequenceBia = traverseBia id

traverseBiaWith :: forall p a b c s t. Biapplicative p => (forall f x. Applicative f => (a -> f x) -> s -> f (t x)) -> (a -> p b c) -> s -> p (t b) (t c) #

A version of `traverseBia` that doesn't care how the traversal is done.

    traverseBia = traverseBiaWith traverse