Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Nondeterministic choice as an algebraic effect.
Warning: Non-linear continuations
The handlers forAllChoices
and toList
call continuations zero or twice.
Don't use them to handle a computation that must ensure linear usage of resources.
Synopsis
- data Choice :: AEffect where
- choose :: z :> zz => Handler Choice z -> a -> a -> Eff zz a
- nil :: z :> zz => Handler Choice z -> Eff zz a
- assume :: z :> zz => Handler Choice z -> Bool -> Eff zz ()
- pick :: z :> zz => Handler Choice z -> [a] -> Eff zz a
- removeFrom :: z :> zz => Handler Choice z -> [a] -> Eff zz (a, [a])
- forAllChoices :: forall a zz. (forall z. Handler Choice z -> Eff (z :& zz) a) -> (a -> Eff zz ()) -> Eff zz ()
- toList :: forall a zz. (forall z. Handler Choice z -> Eff (z :& zz) a) -> Eff zz [a]
- foldChoice :: forall a r zz. (a -> Eff zz r) -> Eff zz r -> (Eff zz r -> Eff zz r -> Eff zz r) -> ScopedEff Choice zz a -> Eff zz r
Operations
choose :: z :> zz => Handler Choice z -> a -> a -> Eff zz a Source #
Choose one of two alternatives. Call the Choose
operation.
assume :: z :> zz => Handler Choice z -> Bool -> Eff zz () Source #
Do nothing if True
. Discard (call nil
) if False
.
removeFrom :: z :> zz => Handler Choice z -> [a] -> Eff zz (a, [a]) Source #
Remove an element from a list, returning the resulting list as well. The order of elements is preserved.
Handlers
forAllChoices :: forall a zz. (forall z. Handler Choice z -> Eff (z :& zz) a) -> (a -> Eff zz ()) -> Eff zz () Source #
Apply a function to every result of the nondeterministic computation.