in-other-words-0.1.1.0: A higher-order effect system where the sky's the limit
Safe HaskellNone
LanguageHaskell2010

Control.Effect.Select

Synopsis

Effect

data Select s m a where Source #

An effect for backtracking search.

Constructors

Select :: (forall r. (a -> m (s, r)) -> m r) -> Select s m a 

Actions

select :: Eff (Select s) m => (forall r. (a -> m (s, r)) -> m r) -> m a Source #

Perform a search: capture the continuation of the program, so that you may test values of a and observe what corresponding s each value would result in at the end of the program (which may be seen as the evaluation of a). When you find a satisfactory a, you may return the associated r.

The way higher-order actions interact with the continuation depends on the interpretation of Select. In general, you cannot expect to interact with the continuation in any meaningful way: for example, you should not assume that you will be able to catch an exception thrown at some point in the future of the computation by using catch on the continuation.

Interpretations

runSelect :: forall s a m p. (Carrier m, Threaders '[ContThreads] m p) => (a -> m s) -> SelectC s a m a -> m a Source #

Run a Select s effect by providing an evaluator for the final result of type a.

Derivs (SelectC s r m) = Select s ': Derivs m
Prims  (SelectC s r m) = Prims m

runSelectFast :: forall s a m p. (Carrier m, Threaders '[ContFastThreads] m p) => (a -> m s) -> SelectFastC s a m a -> m a Source #

Run a Select s effect by providing an evaluator for the final result of type a.

Compared to runSelect, this is quite a bit faster, but is significantly more restrictive in what interpreters are used after it, since there are very few primitive effects that the carrier for runSelectFast is able to thread. In fact, of all the primitive effects featured in this library, only one satisfies ContFastThreads: namely, Reader.

Derivs (SelectFastC s r m) = Select s ': Derivs m
Prims  (SelectFastC s r m) = Prims m

Carriers

type SelectC s r = CompositionC '[ReinterpretC (SelectH r) (Select s) '[Shift (s, r)], ShiftC (s, r)] Source #

type SelectFastC s r = CompositionC '[ReinterpretC (SelectH r) (Select s) '[Shift (s, r)], ShiftFastC (s, r)] Source #