in-other-words-0.1.1.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

type FreshEnumC uniq = CompositionC '[ReinterpretC FreshEnumH (Fresh uniq) '[State uniq], StateC uniq] Source #