Copyright | (C) 2011-2018 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.Functor.Bind.Class
Description
This module is used to resolve the cyclic we get from defining these
classes here rather than in a package upstream. Otherwise we'd get
orphaned heads for many instances on the types in transformers
and bifunctors
.
Synopsis
- class Functor f => Apply f where
- newtype WrappedApplicative f a = WrapApplicative {
- unwrapApplicative :: f a
- newtype MaybeApply f a = MaybeApply {
- runMaybeApply :: Either (f a) a
- (<.*>) :: Apply f => f (a -> b) -> MaybeApply f a -> f b
- (<*.>) :: Apply f => MaybeApply f (a -> b) -> f a -> f b
- traverse1Maybe :: (Traversable t, Apply f) => (a -> f b) -> t a -> MaybeApply f (t b)
- class Apply m => Bind m where
- apDefault :: Bind f => f (a -> b) -> f a -> f b
- returning :: Functor f => f a -> (a -> b) -> f b
- class Bifunctor p => Biapply p where
Applyable functors
class Functor f => Apply f where #
A strong lax semi-monoidal endofunctor.
This is equivalent to an Applicative
without pure
.
Laws:
(.
)<$>
u<.>
v<.>
w = u<.>
(v<.>
w) x<.>
(f<$>
y) = (.
f)<$>
x<.>
y f<$>
(x<.>
y) = (f.
)<$>
x<.>
y
The laws imply that .>
and <.
really ignore their
left and right results, respectively, and really
return their right and left results, respectively.
Specifically,
(mf<$>
m).>
(nf<$>
n) = nf<$>
(m.>
n) (mf<$>
m)<.
(nf<$>
n) = mf<$>
(m<.
n)
Methods
(<.>) :: f (a -> b) -> f a -> f b infixl 4 #
(.>) :: f a -> f b -> f b infixl 4 #
(<.) :: f a -> f b -> f a infixl 4 #
liftF2 :: (a -> b -> c) -> f a -> f b -> f c #
Lift a binary function into a comonad with zipping
Instances
Wrappers
newtype WrappedApplicative f a #
Wrap an Applicative
to be used as a member of Apply
Constructors
WrapApplicative | |
Fields
|
Instances
newtype MaybeApply f a #
Transform an Apply into an Applicative by adding a unit.
Constructors
MaybeApply | |
Fields
|
Instances
(<.*>) :: Apply f => f (a -> b) -> MaybeApply f a -> f b infixl 4 #
Apply a non-empty container of functions to a possibly-empty-with-unit container of values.
(<*.>) :: Apply f => MaybeApply f (a -> b) -> f a -> f b infixl 4 #
Apply a possibly-empty-with-unit container of functions to a non-empty container of values.
traverse1Maybe :: (Traversable t, Apply f) => (a -> f b) -> t a -> MaybeApply f (t b) #
Traverse a Traversable
using Apply
, getting the results back in a MaybeApply
.
Bindable functors
class Apply m => Bind m where #
Minimal definition: Either join
or >>-
If defining both, then the following laws (the default definitions) must hold:
join = (>>- id) m >>- f = join (fmap f m)
Laws:
induced definition of <.>: f <.> x = f >>- (<$> x)
Finally, there are two associativity conditions:
associativity of (>>-): (m >>- f) >>- g == m >>- (\x -> f x >>- g) associativity of join: join . join = join . fmap join
These can both be seen as special cases of the constraint that
associativity of (->-): (f ->- g) ->- h = f ->- (g ->- h)
Instances
Bind [] # | |
Defined in Data.Functor.Bind.Class | |
Bind Maybe # | |
Bind IO # | |
Bind Q # | |
Bind Complex # | |
Bind Min # | |
Bind Max # | |
Bind First # | |
Bind Last # | |
Bind Option # | |
Bind Identity # | |
Bind First # | |
Bind Last # | |
Bind Dual # | |
Bind Sum # | |
Bind Product # | |
Bind Down # | |
Bind NonEmpty # | |
Bind IntMap # | |
Bind Tree # | |
Bind Seq # | |
Bind (Either a) # | |
Bind (V1 :: Type -> Type) # | |
Semigroup m => Bind ((,) m) # | A |
Defined in Data.Functor.Bind.Class | |
Monad m => Bind (WrappedMonad m) # | |
Defined in Data.Functor.Bind.Class Methods (>>-) :: WrappedMonad m a -> (a -> WrappedMonad m b) -> WrappedMonad m b # join :: WrappedMonad m (WrappedMonad m a) -> WrappedMonad m a # | |
Bind (Proxy :: Type -> Type) # | |
Ord k => Bind (Map k) # | |
(Functor m, Monad m) => Bind (MaybeT m) # | |
(Apply m, Monad m) => Bind (ListT m) # | |
(Hashable k, Eq k) => Bind (HashMap k) # | |
Bind f => Bind (Alt f) # | |
Bind m => Bind (IdentityT m) # | |
Bind (Tagged a) # | |
(Bind m, Semigroup w) => Bind (WriterT w m) # | A |
(Bind m, Semigroup w) => Bind (WriterT w m) # | A |
Bind m => Bind (WriterT w m) # | Since: 5.3.6 |
Bind m => Bind (StateT s m) # | |
Bind m => Bind (StateT s m) # | |
Bind m => Bind (ReaderT e m) # | |
(Functor m, Monad m) => Bind (ExceptT e m) # | |
(Functor m, Monad m) => Bind (ErrorT e m) # | |
Bind ((->) m :: Type -> Type) # | |
Defined in Data.Functor.Bind.Class | |
(Bind f, Bind g) => Bind (Product f g) # | |
Bind (ContT r m) # | |
(Bind m, Semigroup w) => Bind (RWST r w s m) # | An |
(Bind m, Semigroup w) => Bind (RWST r w s m) # | An |
Bind m => Bind (RWST r w s m) # | Since: 5.3.6 |
Biappliable bifunctors
class Bifunctor p => Biapply p where #
Minimal complete definition
Methods
(<<.>>) :: p (a -> b) (c -> d) -> p a c -> p b d infixl 4 #
Instances
Biapply (,) # | |
Biapply Arg # | |
Semigroup x => Biapply ((,,) x) # | |
Biapply (Const :: Type -> Type -> Type) # | |
Biapply (Tagged :: Type -> Type -> Type) # | |
(Semigroup x, Semigroup y) => Biapply ((,,,) x y) # | |
(Semigroup x, Semigroup y, Semigroup z) => Biapply ((,,,,) x y z) # | |
Biapply p => Biapply (WrappedBifunctor p) # | |
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 :: Type -> Type -> Type) # | |
Biapply p => Biapply (Flip p) # | |
Apply f => Biapply (Clown f :: Type -> Type -> Type) # | |
(Biapply p, Biapply q) => Biapply (Product p q) # | |
(Apply f, Biapply p) => Biapply (Tannen f p) # | |
(Biapply p, Apply f, Apply g) => Biapply (Biff p f g) # | |