Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- data NonDet :: Effect where
- class Applicative f => Alternative (f :: Type -> Type) where
- runNonDetAll :: Alternative f => Eff (NonDet ': effs) a -> Eff effs (f a)
Documentation
data NonDet :: Effect where Source #
The NonDet
effect provides so-called nondeterministic execution, which
runs all branches of a computation and collects some or all of their results.
Actual execution is not usually truly nondeterministic in the sense that it
is somehow random; rather, NonDet
models nondeterministic binary choice by
executing both possibilities rather than choosing just one.
class Applicative f => Alternative (f :: Type -> Type) 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
runNonDetAll :: Alternative f => Eff (NonDet ': effs) a -> Eff effs (f a) Source #
Handles a NonDet
effect, collecting the results of all branches of the
computation. The results are collected strictly, which means that all
effects are evaluated (even if using an Alternative
that ignores subsequent
results, such as Maybe
).
The result is also built using a left-associated sequence of <|>
calls,
which allows the result to be constructed in constant space if an appropriate
Alternative
instance is used, but can lead to very poor performance for
types with inefficient append operations, such as []
. Consider using a data
structure that supports efficient appends, such as Data.Sequence.Seq
.