{-# LANGUAGE GADTs #-}
module Control.Effect.Cut
(
Cut(..)
, cutfail
, call
, cut
, Algebra
, Has
, run
) where
import Control.Algebra
import Control.Applicative (Alternative(..))
data Cut m k where
Cutfail :: Cut m a
Call :: m a -> Cut m a
cutfail :: Has Cut sig m => m a
cutfail :: m a
cutfail = Cut m a -> m a
forall (eff :: (* -> *) -> * -> *) (sig :: (* -> *) -> * -> *)
(m :: * -> *) a.
(Member eff sig, Algebra sig m) =>
eff m a -> m a
send Cut m a
forall (m :: * -> *) a. Cut m a
Cutfail
{-# INLINE cutfail #-}
call :: Has Cut sig m => m a -> m a
call :: m a -> m a
call m a
m = Cut m a -> m a
forall (eff :: (* -> *) -> * -> *) (sig :: (* -> *) -> * -> *)
(m :: * -> *) a.
(Member eff sig, Algebra sig m) =>
eff m a -> m a
send (m a -> Cut m a
forall (m :: * -> *) a. m a -> Cut m a
Call m a
m)
{-# INLINE call #-}
cut :: (Alternative m, Has Cut sig m) => m ()
cut :: m ()
cut = () -> m ()
forall (f :: * -> *) a. Applicative f => a -> f a
pure () m () -> m () -> m ()
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> m ()
forall (sig :: (* -> *) -> * -> *) (m :: * -> *) a.
Has Cut sig m =>
m a
cutfail
{-# INLINE cut #-}