| 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.Alt
Description
Synopsis
- class Functor f => Alt (f :: Type -> Type) where
- (<!>) :: f a -> f a -> f a
- some :: Applicative f => f a -> f [a]
- many :: Applicative f => f a -> f [a]
- optional :: (Alt f, Applicative f) => f a -> f (Maybe a)
- galt :: (Generic1 f, Alt (Rep1 f)) => f a -> f a -> f a
- module Data.Functor.Apply
Documentation
class Functor f => Alt (f :: Type -> Type) where #
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 distribution" law of
MonadPlus with respect to <.>:
<.> right-distributes over <!>: (a <!> b) <.> c = (a <.> c) <!> (b <.> c)
IO, , Either a and ExceptT e mSTM instead satisfy the
"left catch" law:
pure a <!> b = pure a
Maybe and Identity satisfy both "left distribution" and "left catch".
These variations 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)
Minimal complete definition
Methods
(<!>) :: f a -> f a -> f a infixl 3 #
<|> without a required empty
some :: Applicative f => f a -> f [a] #
many :: Applicative f => f a -> f [a] #
Instances
| Alt Identity # | Choose the first option every time. While 'choose the last option' every time is also valid, this instance satisfies more laws. Since: 5.3.6 |
| Alt First # | |
| Alt Last # | |
| Alt First # | |
| Alt Last # | |
| Alt NonEmpty # | |
| Alt IntMap # | |
| Alt Seq # | |
| Alt IO # | This instance does not actually satisfy the ( |
| Alt Maybe # | |
| Alt [] # | |
Defined in Data.Functor.Alt | |
| MonadPlus m => Alt (WrappedMonad m) # | |
Defined in Data.Functor.Alt Methods (<!>) :: WrappedMonad m a -> WrappedMonad m a -> WrappedMonad m a # some :: Applicative (WrappedMonad m) => WrappedMonad m a -> WrappedMonad m [a] # many :: Applicative (WrappedMonad m) => WrappedMonad m a -> WrappedMonad m [a] # | |
| Alt (Either a) # | |
| Alt (Proxy :: Type -> Type) # | |
| Alt (U1 :: Type -> Type) # | |
| Alt (V1 :: Type -> Type) # | |
| Ord k => Alt (Map k) # | |
| Alternative f => Alt (WrappedApplicative f) # | |
Defined in Data.Functor.Alt Methods (<!>) :: WrappedApplicative f a -> WrappedApplicative f a -> WrappedApplicative f a # some :: Applicative (WrappedApplicative f) => WrappedApplicative f a -> WrappedApplicative f [a] # many :: Applicative (WrappedApplicative f) => WrappedApplicative f a -> WrappedApplicative f [a] # | |
| Alt f => Alt (Lift f) # | |
| (Functor f, Monad f) => Alt (MaybeT f) # | |
| (Hashable k, Eq k) => Alt (HashMap k) # | |
| ArrowPlus a => Alt (WrappedArrow a b) # | |
Defined in Data.Functor.Alt Methods (<!>) :: WrappedArrow a b a0 -> WrappedArrow a b a0 -> WrappedArrow a b a0 # some :: Applicative (WrappedArrow a b) => WrappedArrow a b a0 -> WrappedArrow a b [a0] # many :: Applicative (WrappedArrow a b) => WrappedArrow a b a0 -> WrappedArrow a b [a0] # | |
| Alt f => Alt (Rec1 f) # | |
| Alt f => Alt (Static f a) # | |
| Alt f => Alt (Backwards f) # | |
| (Functor f, Monad f, Semigroup e) => Alt (ExceptT e f) # | |
| Alt f => Alt (IdentityT f) # | |
| Alt f => Alt (ReaderT e f) # | |
| Alt f => Alt (StateT e f) # | |
| Alt f => Alt (StateT e f) # | |
| Alt f => Alt (WriterT w f) # | Since: 5.3.6 |
| Alt f => Alt (WriterT w f) # | |
| Alt f => Alt (WriterT w f) # | |
| Alt f => Alt (Reverse f) # | |
| (Alt f, Alt g) => Alt (Product f g) # | |
| (Alt f, Alt g) => Alt (f :*: g) # | |
| Semigroup c => Alt (K1 i c :: Type -> Type) # | since 5.3.8 |
| (Alt f, Functor g) => Alt (Compose f g) # | |
| (Alt f, Functor g) => Alt (f :.: g) # | Since: 5.3.8 |
| Alt f => Alt (M1 i c f) # | |
| Alt f => Alt (RWST r w s f) # | Since: 5.3.6 |
| Alt f => Alt (RWST r w s f) # | |
| Alt f => Alt (RWST r w s f) # | |
optional :: (Alt f, Applicative f) => f a -> f (Maybe a) #
One or none.
module Data.Functor.Apply