bluefin-algae-0.1.0.0: Algebraic effects and named handlers in Bluefin.
Safe HaskellSafe-Inferred
LanguageHaskell2010

Bluefin.Algae.NonDeterminism

Description

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

Operations

data Choice :: AEffect where Source #

Choice effect.

Constructors

Choose :: a -> a -> Choice a

Choose one of two alternatives.

Nil :: Choice a

No choice.

choose :: z :> zz => Handler Choice z -> a -> a -> Eff zz a Source #

Choose one of two alternatives. Call the Choose operation.

nil :: z :> zz => Handler Choice z -> Eff zz a Source #

No choice. Call the Nil operation.

assume :: z :> zz => Handler Choice z -> Bool -> Eff zz () Source #

Do nothing if True. Discard (call nil) if False.

pick :: z :> zz => Handler Choice z -> [a] -> Eff zz a Source #

Pick an element in a list.

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.

toList :: forall a zz. (forall z. Handler Choice z -> Eff (z :& zz) a) -> Eff zz [a] Source #

Collect the results of a nondeterministic computation in a list.

foldChoice Source #

Arguments

:: forall a r zz. (a -> Eff zz r)

Injection

-> Eff zz r

Identity element

-> (Eff zz r -> Eff zz r -> Eff zz r)

Binary operation

-> ScopedEff Choice zz a 
-> Eff zz r 

Generic Choice handler parameterized by a monoid.