| Copyright | (C) 2011 Edward Kmett, |
|---|---|
| License | BSD-style (see the file LICENSE) |
| Maintainer | Edward Kmett <ekmett@gmail.com> |
| Stability | provisional |
| Portability | portable |
| Safe Haskell | Safe |
| Language | Haskell98 |
Data.Functor.Bind
Description
NB: The definitions exported through Data.Functor.Apply need to be included here because otherwise the instances for the transformers package have orphaned heads.
- class Functor f 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
- liftF2 :: Apply w => (a -> b -> c) -> w a -> w b -> w c
- 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
- (-<<) :: 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 where
The Functor class is used for types that can be mapped over.
Instances of Functor should satisfy the following laws:
fmap id == id fmap (f . g) == fmap f . fmap g
The instances of Functor for lists, Maybe and IO
satisfy these laws.
Minimal complete definition
Instances
($>) :: Functor f => f a -> b -> f b infixl 4
Replace the contents of a functor uniformly with a constant value.
Applyable functors
class Functor f => Apply f where
A strong lax semi-monoidal endofunctor.
This is equivalent to an Applicative without pure.
Laws:
associative composition: (.) <$> u <.> v <.> w = u <.> (v <.> w)
Minimal complete definition
Methods
(<.>) :: f (a -> b) -> f a -> f b infixl 4
(.>) :: f a -> f b -> f b infixl 4
a .> b = const id <$> a <.> b
(<.) :: f a -> f b -> f a infixl 4
a <. b = const <$> a <.> b
Instances
liftF2 :: Apply w => (a -> b -> c) -> w a -> w b -> w c
Lift a binary function into a comonad with zipping
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
| Alternative f => Alternative (WrappedApplicative f) | |
| Functor f => Functor (WrappedApplicative f) | |
| Applicative f => Applicative (WrappedApplicative f) | |
| Applicative f => Apply (WrappedApplicative f) | |
| Alternative f => Alt (WrappedApplicative f) | |
| Alternative f => Plus (WrappedApplicative f) |
newtype MaybeApply f a
Transform a Apply into an Applicative by adding a unit.
Constructors
| MaybeApply | |
Fields
| |
Instances
| Functor f => Functor (MaybeApply f) | |
| Apply f => Applicative (MaybeApply f) | |
| Comonad f => Comonad (MaybeApply f) | |
| Extend f => Extend (MaybeApply f) | |
| Apply f => Apply (MaybeApply f) |
Bindable functors
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)
Minimal complete definition
Nothing
Instances
| Bind [] | |
| Bind IO | |
| Bind Maybe | |
| Bind IntMap | |
| Bind Tree | |
| Bind Seq | |
| Bind Option | |
| Bind NonEmpty | |
| Bind Identity | |
| Bind ((->) m) | |
| Bind (Either a) | |
| Semigroup m => Bind ((,) m) | |
| Monad m => Bind (WrappedMonad m) | |
| Ord k => Bind (Map k) | |
| (Bind m, Monad m) => Bind (MaybeT m) | |
| (Bind m, Monad m) => Bind (ListT m) | |
| Bind m => Bind (IdentityT m) | |
| (Bind m, Semigroup w) => Bind (WriterT w m) | |
| (Bind m, Semigroup w) => Bind (WriterT w m) | |
| Bind m => Bind (StateT s m) | |
| Bind m => Bind (StateT s m) | |
| Bind m => Bind (ReaderT e m) | |
| (Bind m, Monad m) => Bind (ErrorT e m) | |
| Bind (ContT r m) | |
| (Bind f, Bind g) => Bind (Product f g) | |
| (Bind m, Semigroup w) => Bind (RWST r w s m) | |
| (Bind m, Semigroup w) => Bind (RWST r w s m) |