Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- data NonDet (m :: * -> *) k
- class Applicative f => Alternative (f :: * -> *) where
- runNonDet :: (Alternative f, Monad f, Traversable f, Carrier sig m, Effect sig, Applicative m) => Eff (AltC f m) a -> m (f a)
- newtype AltC f m a = AltC {
- runAltC :: m (f a)
Documentation
class Applicative f => Alternative (f :: * -> *) where #
A monoid on applicative functors.
If defined, some
and many
should be the least solutions
of the equations:
The identity of <|>
(<|>) :: f a -> f a -> f a infixl 3 #
An associative binary operation
One or more.
Zero or more.
Instances
Alternative [] | Since: base-2.1 |
Alternative Maybe | Since: base-2.1 |
Alternative IO | Since: base-4.9.0.0 |
Alternative Option | Since: base-4.9.0.0 |
Alternative ZipList | Since: base-4.11.0.0 |
Alternative ReadP | Since: base-4.6.0.0 |
Alternative P | Since: base-4.5.0.0 |
Alternative (U1 :: * -> *) | Since: base-4.9.0.0 |
MonadPlus m => Alternative (WrappedMonad m) | Since: base-2.1 |
Defined in Control.Applicative empty :: WrappedMonad m a # (<|>) :: WrappedMonad m a -> WrappedMonad m a -> WrappedMonad m a # some :: WrappedMonad m a -> WrappedMonad m [a] # many :: WrappedMonad m a -> WrappedMonad m [a] # | |
ArrowPlus a => Alternative (ArrowMonad a) | Since: base-4.6.0.0 |
Defined in Control.Arrow empty :: ArrowMonad a a0 # (<|>) :: ArrowMonad a a0 -> ArrowMonad a a0 -> ArrowMonad a a0 # some :: ArrowMonad a a0 -> ArrowMonad a [a0] # many :: ArrowMonad a a0 -> ArrowMonad a [a0] # | |
Alternative (Proxy :: * -> *) | Since: base-4.9.0.0 |
(Member NonDet sig, Carrier sig carrier) => Alternative (Eff carrier) # | Run computations nondeterministically. run (runNonDet empty) == [] run (runNonDet empty) == Nothing run (runNonDet (pure a <|> pure b)) == [a, b] run (runNonDet (pure a <|> pure b)) == Just a Associativity: run (runNonDet ((pure a <|> pure b) <|> pure c)) == (run (runNonDet (pure a <|> (pure b <|> pure c))) :: [Integer]) run (runNonDet ((pure a <|> pure b) <|> pure c)) == (run (runNonDet (pure a <|> (pure b <|> pure c))) :: Maybe Integer) Left-identity: run (runNonDet (empty <|> pure b)) == (run (runNonDet (pure b)) :: [Integer]) run (runNonDet (empty <|> pure b)) == (run (runNonDet (pure b)) :: Maybe Integer) Right-identity: run (runNonDet (pure a <|> empty)) == (run (runNonDet (pure a)) :: [Integer]) run (runNonDet (pure a <|> empty)) == (run (runNonDet (pure a)) :: Maybe Integer) |
Alternative f => Alternative (Rec1 f) | Since: base-4.9.0.0 |
(ArrowZero a, ArrowPlus a) => Alternative (WrappedArrow a b) | Since: base-2.1 |
Defined in Control.Applicative empty :: WrappedArrow a b a0 # (<|>) :: WrappedArrow a b a0 -> WrappedArrow a b a0 -> WrappedArrow a b a0 # some :: WrappedArrow a b a0 -> WrappedArrow a b [a0] # many :: WrappedArrow a b a0 -> WrappedArrow a b [a0] # | |
Alternative f => Alternative (Alt f) | |
(Functor m, Monad m, Error e) => Alternative (ErrorT e m) | |
(Alternative f, Alternative g) => Alternative (f :*: g) | Since: base-4.9.0.0 |
(Alternative f, Alternative g) => Alternative (Product f g) | Since: base-4.9.0.0 |
Alternative f => Alternative (M1 i c f) | Since: base-4.9.0.0 |
(Alternative f, Applicative g) => Alternative (f :.: g) | Since: base-4.9.0.0 |
(Alternative f, Applicative g) => Alternative (Compose f g) | Since: base-4.9.0.0 |
runNonDet :: (Alternative f, Monad f, Traversable f, Carrier sig m, Effect sig, Applicative m) => Eff (AltC f m) a -> m (f a) Source #
Run a NonDet
effect, collecting all branches’ results into an Alternative
functor.
Using '[]' as the Alternative
functor will produce all results, while Maybe
will return only the first.
run (runNonDet (pure a)) == [a]
run (runNonDet (pure a)) == Just a