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 | Haskell98 |
Data.Biapplicative
Contents
Description
- class Bifunctor p => Biapplicative p where
- (<<$>>) :: (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)
- module Data.Bifunctor
Biapplicative bifunctors
class Bifunctor p => Biapplicative p where Source #
Methods
bipure :: a -> b -> p a b Source #
(<<*>>) :: p (a -> b) (c -> d) -> p a c -> p b d infixl 4 Source #
biliftA2 :: (a -> b -> c) -> (d -> e -> f) -> p a d -> p b e -> p c f Source #
Lift binary functions
Instances
Biapplicative (,) Source # | |
Biapplicative Arg Source # | |
Monoid x => Biapplicative ((,,) x) Source # | |
Biapplicative (Const *) Source # | |
Biapplicative (Tagged *) Source # | |
(Monoid x, Monoid y) => Biapplicative ((,,,) x y) Source # | |
(Monoid x, Monoid y, Monoid z) => Biapplicative ((,,,,) x y z) Source # | |
Applicative f => Biapplicative (Clown * * f) Source # | |
Biapplicative p => Biapplicative (Flip * * p) Source # | |
Applicative g => Biapplicative (Joker * * g) Source # | |
Biapplicative p => Biapplicative (WrappedBifunctor * * p) Source # | |
(Monoid x, Monoid y, Monoid z, Monoid w) => Biapplicative ((,,,,,) x y z w) Source # | |
(Biapplicative f, Biapplicative g) => Biapplicative (Product * * f g) Source # | |
(Monoid x, Monoid y, Monoid z, Monoid w, Monoid v) => Biapplicative ((,,,,,,) x y z w v) Source # | |
(Applicative f, Biapplicative p) => Biapplicative (Tannen * * * f p) Source # | |
(Biapplicative p, Applicative f, Applicative g) => Biapplicative (Biff * * * * p f g) Source # | |
(<<**>>) :: Biapplicative p => p a c -> p (a -> b) (c -> d) -> p b d infixl 4 Source #
biliftA3 :: Biapplicative 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
traverseBia :: (Traversable t, Biapplicative p) => (a -> p b c) -> t a -> p (t b) (t c) Source #
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
ftraverseBia
(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 aBiapplicative
Q
is a functiont :: P a b -> Q a b
preserving the
Biapplicative
operations. That is,
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) Source #
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) Source #
A version of traverseBia
that doesn't care how the traversal is
done.
traverseBia
= traverseBiaWith traverse
module Data.Bifunctor