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.Functor.Bind
Description
Synopsis
- class Functor (f :: Type -> Type) where
- (<$>) :: Functor f => (a -> b) -> f a -> f b
- ($>) :: Functor f => f a -> b -> f b
- class Functor f => Apply f where
- (<..>) :: Apply w => w a -> w (a -> b) -> w b
- liftF3 :: Apply w => (a -> b -> c -> d) -> w a -> w b -> w c -> w d
- newtype WrappedApplicative f a = WrapApplicative {
- unwrapApplicative :: f a
- newtype MaybeApply f a = MaybeApply {
- runMaybeApply :: Either (f a) a
- class Apply m => Bind m where
- gbind :: (Generic1 m, Bind (Rep1 m)) => m a -> (a -> m b) -> m b
- (-<<) :: Bind m => (a -> m b) -> m a -> m b
- (-<-) :: Bind m => (b -> m c) -> (a -> m b) -> a -> m c
- (->-) :: Bind m => (a -> m b) -> (b -> m c) -> a -> m c
- apDefault :: Bind f => f (a -> b) -> f a -> f b
- returning :: Functor f => f a -> (a -> b) -> f b
Functors
class Functor (f :: Type -> Type) where #
Minimal complete definition
Instances
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
Apply ZipList # | |
Apply Complex # | |
Apply Identity # | |
Apply First # | |
Apply Last # | |
Apply Down # | |
Apply First # | |
Apply Last # | |
Apply Max # | |
Apply Min # | |
Apply Dual # | |
Apply Product # | |
Apply Sum # | |
Apply NonEmpty # | |
Apply Par1 # | |
Apply IntMap # | An |
Apply Seq # | |
Apply Tree # | |
Apply IO # | |
Apply Q # | |
Apply Maybe # | |
Apply List # | |
Monad m => Apply (WrappedMonad m) # | |
Defined in Data.Functor.Bind.Class | |
Apply (Either a) # | |
Apply (Proxy :: Type -> Type) # | |
Apply (U1 :: Type -> Type) # | |
Apply (V1 :: Type -> Type) # | A |
Ord k => Apply (Map k) # | A 'Map k' is not |
Apply f => Apply (MaybeApply f) # | |
Defined in Data.Functor.Bind.Class Methods (<.>) :: MaybeApply f (a -> b) -> MaybeApply f a -> MaybeApply f b # (.>) :: MaybeApply f a -> MaybeApply f b -> MaybeApply f b # (<.) :: MaybeApply f a -> MaybeApply f b -> MaybeApply f a # liftF2 :: (a -> b -> c) -> MaybeApply f a -> MaybeApply f b -> MaybeApply f c # | |
Applicative f => Apply (WrappedApplicative f) # | |
Defined in Data.Functor.Bind.Class Methods (<.>) :: WrappedApplicative f (a -> b) -> WrappedApplicative f a -> WrappedApplicative f b # (.>) :: WrappedApplicative f a -> WrappedApplicative f b -> WrappedApplicative f b # (<.) :: WrappedApplicative f a -> WrappedApplicative f b -> WrappedApplicative f a # liftF2 :: (a -> b -> c) -> WrappedApplicative f a -> WrappedApplicative f b -> WrappedApplicative f c # | |
Apply f => Apply (Lift f) # | |
(Functor m, Monad m) => Apply (MaybeT m) # | |
(Hashable k, Eq k) => Apply (HashMap k) # | A 'HashMap k' is not |
Semigroup m => Apply ((,) m) # | A |
Arrow a => Apply (WrappedArrow a b) # | |
Defined in Data.Functor.Bind.Class Methods (<.>) :: WrappedArrow a b (a0 -> b0) -> WrappedArrow a b a0 -> WrappedArrow a b b0 # (.>) :: WrappedArrow a b a0 -> WrappedArrow a b b0 -> WrappedArrow a b b0 # (<.) :: WrappedArrow a b a0 -> WrappedArrow a b b0 -> WrappedArrow a b a0 # liftF2 :: (a0 -> b0 -> c) -> WrappedArrow a b a0 -> WrappedArrow a b b0 -> WrappedArrow a b c # | |
Semigroup m => Apply (Const m :: Type -> Type) # | A |
Apply f => Apply (Alt f) # | |
Apply f => Apply (Rec1 f) # | |
Biapply p => Apply (Join p) # | |
(Semigroup e, Apply w) => Apply (EnvT e w) # | An |
(Apply w, Semigroup s) => Apply (StoreT s w) # | A |
Apply w => Apply (TracedT m w) # | |
Apply f => Apply (Static f a) # | |
Apply (Tagged a) # | |
Apply f => Apply (Backwards f) # | |
(Functor m, Monad m) => Apply (ExceptT e m) # | |
Apply w => Apply (IdentityT w) # | |
Apply m => Apply (ReaderT e m) # | |
Bind m => Apply (StateT s m) # | |
Bind m => Apply (StateT s m) # | |
Bind m => Apply (WriterT w m) # | Since: 5.3.6 |
(Apply m, Semigroup w) => Apply (WriterT w m) # | A |
(Apply m, Semigroup w) => Apply (WriterT w m) # | A |
Semigroup f => Apply (Constant f :: Type -> Type) # | A |
Apply f => Apply (Reverse f) # | |
(Apply f, Apply g) => Apply (Product f g) # | |
(Apply f, Apply g) => Apply (f :*: g) # | |
Semigroup c => Apply (K1 i c :: Type -> Type) # | A |
Apply (Cokleisli w a) # | |
Defined in Data.Functor.Bind.Class | |
Apply (ContT r m) # | |
Apply ((->) m) # | |
(Apply f, Apply g) => Apply (Compose f g) # | |
(Apply f, Apply g) => Apply (f :.: g) # | |
Apply f => Apply (M1 i t f) # | |
Bind m => Apply (RWST r w s m) # | Since: 5.3.6 |
Defined in Data.Functor.Bind.Class | |
(Bind m, Semigroup w) => Apply (RWST r w s m) # | An |
Defined in Data.Functor.Bind.Class | |
(Bind m, Semigroup w) => Apply (RWST r w s m) # | An |
Defined in Data.Functor.Bind.Class |
(<..>) :: Apply w => w a -> w (a -> b) -> w b infixl 4 #
A variant of <.>
with the arguments reversed.
liftF3 :: Apply w => (a -> b -> c -> d) -> w a -> w b -> w c -> w d #
Lift a ternary function into a comonad with zipping
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
Bindable functors
class Apply m => Bind m where #
A Monad
sans return
.
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 Complex # | |
Defined in Data.Functor.Bind.Class | |
Bind Identity # | |
Defined in Data.Functor.Bind.Class | |
Bind First # | |
Defined in Data.Functor.Bind.Class | |
Bind Last # | |
Defined in Data.Functor.Bind.Class | |
Bind Down # | |
Defined in Data.Functor.Bind.Class | |
Bind First # | |
Defined in Data.Functor.Bind.Class | |
Bind Last # | |
Defined in Data.Functor.Bind.Class | |
Bind Max # | |
Defined in Data.Functor.Bind.Class | |
Bind Min # | |
Defined in Data.Functor.Bind.Class | |
Bind Dual # | |
Defined in Data.Functor.Bind.Class | |
Bind Product # | |
Defined in Data.Functor.Bind.Class | |
Bind Sum # | |
Defined in Data.Functor.Bind.Class | |
Bind NonEmpty # | |
Defined in Data.Functor.Bind.Class | |
Bind Par1 # | Since: 5.3.8 |
Defined in Data.Functor.Bind.Class | |
Bind IntMap # | An |
Defined in Data.Functor.Bind.Class | |
Bind Seq # | |
Defined in Data.Functor.Bind.Class | |
Bind Tree # | |
Defined in Data.Functor.Bind.Class | |
Bind IO # | |
Defined in Data.Functor.Bind.Class | |
Bind Q # | |
Defined in Data.Functor.Bind.Class | |
Bind Maybe # | |
Defined in Data.Functor.Bind.Class | |
Bind List # | |
Defined in Data.Functor.Bind.Class | |
Monad m => Bind (WrappedMonad m) # | |
Defined in Data.Functor.Bind.Class | |
Bind (Either a) # | |
Defined in Data.Functor.Bind.Class | |
Bind (Proxy :: Type -> Type) # | |
Defined in Data.Functor.Bind.Class | |
Bind (U1 :: Type -> Type) # | Since: 5.3.8 |
Defined in Data.Functor.Bind.Class | |
Bind (V1 :: Type -> Type) # | A |
Defined in Data.Functor.Bind.Class | |
Ord k => Bind (Map k) # | A 'Map k' is not a |
Defined in Data.Functor.Bind.Class | |
(Functor m, Monad m) => Bind (MaybeT m) # | |
Defined in Data.Functor.Bind.Class | |
(Hashable k, Eq k) => Bind (HashMap k) # | A 'HashMap k' is not a |
Semigroup m => Bind ((,) m) # | A |
Defined in Data.Functor.Bind.Class | |
Bind f => Bind (Alt f) # | |
Defined in Data.Functor.Bind.Class | |
Bind m => Bind (Rec1 m) # | Since: 5.3.8 |
Defined in Data.Functor.Bind.Class | |
Bind (Tagged a) # | |
(Functor m, Monad m) => Bind (ExceptT e m) # | |
Defined in Data.Functor.Bind.Class | |
Bind m => Bind (IdentityT m) # | |
Bind m => Bind (ReaderT e m) # | |
Defined in Data.Functor.Bind.Class | |
Bind m => Bind (StateT s m) # | |
Defined in Data.Functor.Bind.Class | |
Bind m => Bind (StateT s m) # | |
Defined in Data.Functor.Bind.Class | |
Bind m => Bind (WriterT w m) # | Since: 5.3.6 |
Defined in Data.Functor.Bind.Class | |
(Bind m, Semigroup w) => Bind (WriterT w m) # | A |
Defined in Data.Functor.Bind.Class | |
(Bind m, Semigroup w) => Bind (WriterT w m) # | A |
Defined in Data.Functor.Bind.Class | |
(Bind f, Bind g) => Bind (Product f g) # | |
Defined in Data.Functor.Bind.Class | |
(Bind f, Bind g) => Bind (f :*: g) # | Since: 5.3.8 |
Defined in Data.Functor.Bind.Class | |
Bind (ContT r m) # | |
Defined in Data.Functor.Bind.Class | |
Bind ((->) m) # | |
Defined in Data.Functor.Bind.Class | |
Bind f => Bind (M1 i c f) # | Since: 5.3.8 |
Defined in Data.Functor.Bind.Class | |
Bind m => Bind (RWST r w s m) # | Since: 5.3.6 |
Defined in Data.Functor.Bind.Class | |
(Bind m, Semigroup w) => Bind (RWST r w s m) # | An |
Defined in Data.Functor.Bind.Class | |
(Bind m, Semigroup w) => Bind (RWST r w s m) # | An |
Defined in Data.Functor.Bind.Class |
gbind :: (Generic1 m, Bind (Rep1 m)) => m a -> (a -> m b) -> m b #
Generic (>>-)
. Caveats:
- Will not compile if
m
is a sum type. - Will not compile if
m
contains fields that do not mention its type variable. - Will not compile if
m
contains fields where the type variable appears underneath the composition of type constructors (e.g.,f (g a)
). - May do redundant work, due to the nature of the
Bind
instance for (:*:
)
Since: 5.3.8