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

Control.Effect.Fresh

Synopsis

Effects

data Fresh uniq :: Effect where Source #

An effect for creating unique objects which may be used as references, a la Unique. Polymorphic code making use of Fresh is expected to place constraints upon uniq as necessary.

Any interpreter for Fresh has the responsibilty of ensuring that any call to fresh produces an object that never compares equal to an object produced by a previous call to fresh.

Constructors

Fresh :: Fresh uniq m uniq 

Actions

fresh :: Eff (Fresh uniq) m => m uniq Source #

Interpretations

freshToIO :: Eff (Embed IO) m => FreshToIOC m a -> m a Source #

Runs a Fresh effect through generating Uniques using IO.

Derivs (FreshToIOC m) = Fresh Unique ': Derivs m
Prims  (FreshToIOC m) = Prims m

runFreshEnumIO :: forall uniq m a. (Enum uniq, Eff (Embed IO) m) => InterpretReifiedC (Fresh uniq) m a -> m a Source #

Run a Fresh effect through atomic operations in IO by specifying an Enum to be used as the type of unique objects.

This is a safe variant of runFreshEnum.

This has a higher-rank type, as it makes use of InterpretReifiedC. This makes runFreshEnumIO very difficult to use partially applied. In particular, it can't be composed using ..

If performance is secondary, consider using the slower runFreshEnumIOSimple, which doesn't have a higher-rank type.

Unsafe interpretations

runFreshEnum :: forall uniq m a p. (Enum uniq, Threaders '[StateThreads] m p, Carrier m) => FreshEnumC uniq m a -> m a Source #

Run a Fresh effect purely by specifying an Enum to be used as the type of unique objects.

Beware: This is safe only if:

  1. This is run after all interpreters which may revert local state or produce multiple, inconsistent instances of local state. This includes interpreters that may backtrack or produce multiple results (such as runError or runNonDet).
  2. You don't use any interpreter which may cause the final monad to revert local state or produce multiple, inconsistent instances of local state. This includes errorToIO and asyncToIO.

Prefer freshToIO or runFreshEnumIO whenever possible.

Derivs (FreshEnumC uniq m) = Fresh uniq ': Derivs m
Prims  (FreshEnumC uniq m) = Prims m

Simple variants of interpretations

runFreshEnumIOSimple :: forall uniq m a p. (Enum uniq, Eff (Embed IO) m, Threaders '[ReaderThreads] m p) => InterpretSimpleC (Fresh uniq) m a -> m a Source #

Run a Fresh effect though atomic operations in IO by specifying an Enum to be used as the type of unique objects.

This is a less performant version of runFreshEnumIO that doesn't have a higher-rank type, making it much easier to use partially applied.

Threading constraints

class (forall s. Threads (StateT s) p) => StateThreads p Source #

StateThreads accepts the following primitive effects:

Instances

Instances details
(forall s. Threads (StateT s) p) => StateThreads p Source # 
Instance details

Defined in Control.Effect.Internal.State

Carriers

data FreshEnumC uniq m a Source #

Instances

Instances details
MonadBase b m => MonadBase b (FreshEnumC uniq m) Source # 
Instance details

Defined in Control.Effect.Fresh

Methods

liftBase :: b α -> FreshEnumC uniq m α #

MonadBaseControl b m => MonadBaseControl b (FreshEnumC uniq m) Source # 
Instance details

Defined in Control.Effect.Fresh

Associated Types

type StM (FreshEnumC uniq m) a #

Methods

liftBaseWith :: (RunInBase (FreshEnumC uniq m) b -> b a) -> FreshEnumC uniq m a #

restoreM :: StM (FreshEnumC uniq m) a -> FreshEnumC uniq m a #

MonadTrans (FreshEnumC uniq) Source # 
Instance details

Defined in Control.Effect.Fresh

Methods

lift :: Monad m => m a -> FreshEnumC uniq m a #

MonadTransControl (FreshEnumC uniq) Source # 
Instance details

Defined in Control.Effect.Fresh

Associated Types

type StT (FreshEnumC uniq) a #

Methods

liftWith :: Monad m => (Run (FreshEnumC uniq) -> m a) -> FreshEnumC uniq m a #

restoreT :: Monad m => m (StT (FreshEnumC uniq) a) -> FreshEnumC uniq m a #

Monad m => Monad (FreshEnumC uniq m) Source # 
Instance details

Defined in Control.Effect.Fresh

Methods

(>>=) :: FreshEnumC uniq m a -> (a -> FreshEnumC uniq m b) -> FreshEnumC uniq m b #

(>>) :: FreshEnumC uniq m a -> FreshEnumC uniq m b -> FreshEnumC uniq m b #

return :: a -> FreshEnumC uniq m a #

Functor m => Functor (FreshEnumC uniq m) Source # 
Instance details

Defined in Control.Effect.Fresh

Methods

fmap :: (a -> b) -> FreshEnumC uniq m a -> FreshEnumC uniq m b #

(<$) :: a -> FreshEnumC uniq m b -> FreshEnumC uniq m a #

MonadFix m => MonadFix (FreshEnumC uniq m) Source # 
Instance details

Defined in Control.Effect.Fresh

Methods

mfix :: (a -> FreshEnumC uniq m a) -> FreshEnumC uniq m a #

MonadFail m => MonadFail (FreshEnumC uniq m) Source # 
Instance details

Defined in Control.Effect.Fresh

Methods

fail :: String -> FreshEnumC uniq m a #

Monad m => Applicative (FreshEnumC uniq m) Source # 
Instance details

Defined in Control.Effect.Fresh

Methods

pure :: a -> FreshEnumC uniq m a #

(<*>) :: FreshEnumC uniq m (a -> b) -> FreshEnumC uniq m a -> FreshEnumC uniq m b #

liftA2 :: (a -> b -> c) -> FreshEnumC uniq m a -> FreshEnumC uniq m b -> FreshEnumC uniq m c #

(*>) :: FreshEnumC uniq m a -> FreshEnumC uniq m b -> FreshEnumC uniq m b #

(<*) :: FreshEnumC uniq m a -> FreshEnumC uniq m b -> FreshEnumC uniq m a #

MonadIO m => MonadIO (FreshEnumC uniq m) Source # 
Instance details

Defined in Control.Effect.Fresh

Methods

liftIO :: IO a -> FreshEnumC uniq m a #

MonadPlus m => Alternative (FreshEnumC uniq m) Source # 
Instance details

Defined in Control.Effect.Fresh

Methods

empty :: FreshEnumC uniq m a #

(<|>) :: FreshEnumC uniq m a -> FreshEnumC uniq m a -> FreshEnumC uniq m a #

some :: FreshEnumC uniq m a -> FreshEnumC uniq m [a] #

many :: FreshEnumC uniq m a -> FreshEnumC uniq m [a] #

MonadPlus m => MonadPlus (FreshEnumC uniq m) Source # 
Instance details

Defined in Control.Effect.Fresh

Methods

mzero :: FreshEnumC uniq m a #

mplus :: FreshEnumC uniq m a -> FreshEnumC uniq m a -> FreshEnumC uniq m a #

MonadThrow m => MonadThrow (FreshEnumC uniq m) Source # 
Instance details

Defined in Control.Effect.Fresh

Methods

throwM :: Exception e => e -> FreshEnumC uniq m a #

MonadCatch m => MonadCatch (FreshEnumC uniq m) Source # 
Instance details

Defined in Control.Effect.Fresh

Methods

catch :: Exception e => FreshEnumC uniq m a -> (e -> FreshEnumC uniq m a) -> FreshEnumC uniq m a #

MonadMask m => MonadMask (FreshEnumC uniq m) Source # 
Instance details

Defined in Control.Effect.Fresh

Methods

mask :: ((forall a. FreshEnumC uniq m a -> FreshEnumC uniq m a) -> FreshEnumC uniq m b) -> FreshEnumC uniq m b #

uninterruptibleMask :: ((forall a. FreshEnumC uniq m a -> FreshEnumC uniq m a) -> FreshEnumC uniq m b) -> FreshEnumC uniq m b #

generalBracket :: FreshEnumC uniq m a -> (a -> ExitCase b -> FreshEnumC uniq m c) -> (a -> FreshEnumC uniq m b) -> FreshEnumC uniq m (b, c) #

(Carrier m, Enum uniq, Threads (StateT uniq) (Prims m)) => Carrier (FreshEnumC uniq m) Source # 
Instance details

Defined in Control.Effect.Fresh

Associated Types

type Derivs (FreshEnumC uniq m) :: [Effect] Source #

type Prims (FreshEnumC uniq m) :: [Effect] Source #

Methods

algPrims :: Algebra' (Prims (FreshEnumC uniq m)) (FreshEnumC uniq m) a Source #

reformulate :: Monad z => Reformulation' (Derivs (FreshEnumC uniq m)) (Prims (FreshEnumC uniq m)) (FreshEnumC uniq m) z a Source #

algDerivs :: Algebra' (Derivs (FreshEnumC uniq m)) (FreshEnumC uniq m) a Source #

type StT (FreshEnumC uniq) a Source # 
Instance details

Defined in Control.Effect.Fresh

type StT (FreshEnumC uniq) a
type Derivs (FreshEnumC uniq m) Source # 
Instance details

Defined in Control.Effect.Fresh

type Derivs (FreshEnumC uniq m)
type Prims (FreshEnumC uniq m) Source # 
Instance details

Defined in Control.Effect.Fresh

type Prims (FreshEnumC uniq m)
type StM (FreshEnumC uniq m) a Source # 
Instance details

Defined in Control.Effect.Fresh

type StM (FreshEnumC uniq m) a