Navigation

Choice

Non-deterministic choice effect: choose/fail/guard with list handler.

choose

choose: non-deterministic selection from a list of alternatives; the handler determines exploration strategy (e.g. listAll for all branches).

choose : [a] -> Computation a

Non-deterministic choice from a list of alternatives. The handler determines how alternatives are explored.

fail

fail: abort the current non-deterministic branch; equivalent to choose [] with an empty-alternatives short-circuit.

fail : Computation a

Fail the current branch of non-deterministic computation. Equivalent to choose [].

guard

guard: continue when the predicate is true, fail the branch when false; threads boolean predicates into non-deterministic search.

guard : bool -> Computation null

Guard a condition: continue if true, fail if false.

initialState

choice.initialState: starting state { results = []; pending = []; } for the listAll handler; pair with handle to run.

Initial state for the listAll handler.

listAll

choice.listAll: handler exploring every non-deterministic branch and accumulating results into state.results; list-monad semantics.

Handler that explores all non-deterministic branches and returns a list of all results. Empty choices abort that branch.

State is { results : [a], pending : [Computation a] }. After handling, results are in state.results.

let r = handle { handlers = choice.listAll; state = choice.initialState; } comp;
in r.state.results