| Portability | portable |
|---|---|
| Stability | provisional |
| Maintainer | Edward Kmett <ekmett@gmail.com> |
Data.Functor.Alt
Description
- class Apply f => Alt f where
- (<!>) :: f a -> f a -> f a
- module Data.Functor.Apply
Documentation
class Apply f => Alt f whereSource
Laws:
<!> is associative: (a <!> b) <!> c = a <!> (b <!> c) <$> left-distributes over <!>: f <$> (a <!> b) = (f <$> a) <!> (f <$> b)
If extended to an Alternative then <!> should equal <|>.
Ideally, an instance of Alt also satisfies the "left distributon" law of
MonadPlus:
<.> right-distributes over <!>: (a <!> b) <.> c = (a <.> c) <!> (b <.> c)
But Maybe, IO, , Either a, and ErrorT e mSTM satisfy the alternative
"left catch" law instead:
pure a <!> b = pure a
However, this variation cannot be stated purely in terms of the dependencies of Alt.
When and if MonadPlus is successfully refactored, this class should also be refactored to remove these instances.
The right distributive law should extend in the cases where the a Bind or Monad is
provided to yield variations of the right distributive law:
(m <!> n) >>- f = (m >>- f) <!> (m >>- f) (m <!> n) >>= f = (m >>= f) <!> (m >>= f)
Instances
| Alt [] | |
| Alt IO | This instance does not actually satisfy the (.) right distributive law It instead satisfies the Left-Catch law |
| Alt Maybe | |
| Alt Seq | |
| Alt IntMap | |
| Alt Option | |
| Alt (Either a) | |
| MonadPlus m => Alt (WrappedMonad m) | |
| Ord k => Alt (Map k) | |
| Apply f => Alt (MaybeT f) | |
| Apply f => Alt (ListT f) | |
| Alt f => Alt (IdentityT f) | |
| Alternative f => Alt (WrappedApplicative f) | |
| ArrowPlus a => Alt (WrappedArrow a b) | |
| (Alt f, Semigroup w) => Alt (WriterT w f) | |
| (Alt f, Semigroup w) => Alt (WriterT w f) | |
| (Bind f, Alt f) => Alt (StateT e f) | |
| (Bind f, Alt f) => Alt (StateT e f) | |
| Alt f => Alt (ReaderT e f) | |
| Apply f => Alt (ErrorT e f) | |
| (Bind f, Alt f, Semigroup w) => Alt (RWST r w s f) | |
| (Bind f, Alt f, Semigroup w) => Alt (RWST r w s f) |
module Data.Functor.Apply