fused-effects-0.4.0.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) => Carrier (Fresh :+: sig) (FreshC m) Source # 
Instance details

Defined in Control.Effect.Fresh

Methods

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 :: Functor m => 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
MonadTrans FreshC Source # 
Instance details

Defined in Control.Effect.Fresh

Methods

lift :: Monad m => m a -> FreshC m a #

Monad m => Monad (FreshC m) Source # 
Instance details

Defined in Control.Effect.Fresh

Methods

(>>=) :: FreshC m a -> (a -> FreshC m b) -> FreshC m b #

(>>) :: FreshC m a -> FreshC m b -> FreshC m b #

return :: a -> FreshC m a #

fail :: String -> FreshC m a #

Functor m => Functor (FreshC m) Source # 
Instance details

Defined in Control.Effect.Fresh

Methods

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

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

MonadFail m => MonadFail (FreshC m) Source # 
Instance details

Defined in Control.Effect.Fresh

Methods

fail :: String -> FreshC m a #

Monad m => Applicative (FreshC m) Source # 
Instance details

Defined in Control.Effect.Fresh

Methods

pure :: a -> FreshC m a #

(<*>) :: FreshC m (a -> b) -> FreshC m a -> FreshC m b #

liftA2 :: (a -> b -> c) -> FreshC m a -> FreshC m b -> FreshC m c #

(*>) :: FreshC m a -> FreshC m b -> FreshC m b #

(<*) :: FreshC m a -> FreshC m b -> FreshC m a #

MonadIO m => MonadIO (FreshC m) Source # 
Instance details

Defined in Control.Effect.Fresh

Methods

liftIO :: IO a -> FreshC m a #

(Alternative m, Monad m) => Alternative (FreshC m) Source # 
Instance details

Defined in Control.Effect.Fresh

Methods

empty :: FreshC m a #

(<|>) :: FreshC m a -> FreshC m a -> FreshC m a #

some :: FreshC m a -> FreshC m [a] #

many :: FreshC m a -> FreshC m [a] #

(Alternative m, Monad m) => MonadPlus (FreshC m) Source # 
Instance details

Defined in Control.Effect.Fresh

Methods

mzero :: FreshC m a #

mplus :: FreshC m a -> FreshC m a -> FreshC m a #

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

Defined in Control.Effect.Fresh

Methods

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