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

Safe HaskellNone
LanguageHaskell2010

Control.Effect.Fresh

Synopsis

Documentation

data Fresh m k Source #

Constructors

Fresh (Int -> k) 
Reset (m b) (b -> k) 
Instances
Effect Fresh Source # 
Instance details

Defined in Control.Effect.Fresh

Methods

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

HFunctor Fresh Source # 
Instance details

Defined in Control.Effect.Fresh

Methods

fmap' :: (a -> b) -> Fresh m a -> Fresh m b Source #

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

Functor (Fresh m) Source # 
Instance details

Defined in Control.Effect.Fresh

Methods

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

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

(Carrier sig m, Effect sig, Monad m) => Carrier (Fresh :+: sig) (FreshC m) Source # 
Instance details

Defined in Control.Effect.Fresh

Methods

ret :: a -> FreshC m a Source #

eff :: (Fresh :+: sig) (FreshC m) (FreshC m a) -> FreshC m a Source #

fresh :: (Member Fresh sig, Carrier sig m) => m Int Source #

Produce a fresh (i.e. unique) Int.

run (runFresh (replicateM n fresh)) == nub (run (runFresh (replicateM n fresh)))

resetFresh :: (Member Fresh sig, Carrier sig m) => m a -> m a Source #

Reset the fresh counter after running a computation.

run (runFresh (resetFresh (replicateM m fresh) *> replicateM n fresh)) == run (runFresh (replicateM n fresh))

runFresh :: (Carrier sig m, Effect sig, Monad m) => Eff (FreshC m) a -> m a Source #

Run a Fresh effect counting up from 0.

run (runFresh (replicateM n fresh)) == [0..pred n]
run (runFresh (replicateM n fresh *> pure b)) == b

newtype FreshC m a Source #

Constructors

FreshC 

Fields

Instances
(Carrier sig m, Effect sig, Monad m) => Carrier (Fresh :+: sig) (FreshC m) Source # 
Instance details

Defined in Control.Effect.Fresh

Methods

ret :: a -> FreshC m a Source #

eff :: (Fresh :+: sig) (FreshC m) (FreshC m a) -> FreshC m a Source #