fused-effects-0.1.2.1: A fast, flexible, fused effect system.

Safe HaskellNone
LanguageHaskell2010

Control.Effect.Cut

Synopsis

Documentation

data Cut m k #

Cut effects are used with NonDet to provide control over backtracking.

Constructors

Cutfail 
Call (m a) (a -> k) 
Instances
Effect Cut # 
Instance details

Defined in Control.Effect.Cut

Methods

handle :: Functor f => f () -> (forall x. f (m x) -> n (f x)) -> Cut m (m a) -> Cut n (n (f a)) #

HFunctor Cut # 
Instance details

Defined in Control.Effect.Cut

Methods

fmap' :: (a -> b) -> Cut m a -> Cut m b #

hmap :: (forall x. m x -> n x) -> Cut m a -> Cut n a #

Functor (Cut m) # 
Instance details

Defined in Control.Effect.Cut

Methods

fmap :: (a -> b) -> Cut m a -> Cut m b #

(<$) :: a -> Cut m b -> Cut m a #

(Alternative m, Carrier sig m, Effect sig, Monad m) => Carrier (Cut :+: (NonDet :+: sig)) (CutC m) # 
Instance details

Defined in Control.Effect.Cut

Methods

ret :: a -> CutC m a #

eff :: (Cut :+: (NonDet :+: sig)) (CutC m) (CutC m a) -> CutC m a #

cutfail :: (Carrier sig m, Member Cut sig) => m a #

Fail the current branch, and prevent backtracking within the nearest enclosing call (if any).

Contrast with empty, which fails the current branch but allows backtracking.

run (runNonDet (runCut (cutfail <|> pure a))) == []
run (runNonDet (runCut (pure a <|> cutfail))) == [a]

call :: (Carrier sig m, Member Cut sig) => m a -> m a #

Delimit the effect of cutfails, allowing backtracking to resume.

run (runNonDet (runCut (call (cutfail <|> pure a) <|> pure b))) == [b]

cut :: (Alternative m, Carrier sig m, Member Cut sig) => m () #

Commit to the current branch, preventing backtracking within the nearest enclosing call (if any) on failure.

run (runNonDet (runCut (pure a <|> cut *> pure b))) == [a, b]
run (runNonDet (runCut (cut *> pure a <|> pure b))) == [a]
run (runNonDet (runCut (cut *> empty <|> pure a))) == []

runCut :: (Alternative m, Carrier sig m, Effect sig, Monad m) => Eff (CutC m) a -> m a #

Run a Cut effect within an underlying Alternative instance (typically Eff carrying a NonDet effect).

run (runNonDetOnce (runCut (pure a))) == Just a

newtype CutC m a #

Constructors

CutC 

Fields

Instances
(Alternative m, Carrier sig m, Effect sig, Monad m) => Carrier (Cut :+: (NonDet :+: sig)) (CutC m) # 
Instance details

Defined in Control.Effect.Cut

Methods

ret :: a -> CutC m a #

eff :: (Cut :+: (NonDet :+: sig)) (CutC m) (CutC m a) -> CutC m a #