polysemy-zoo-0.8.2.0: Experimental, user-contributed effects and interpreters for polysemy
Safe HaskellSafe-Inferred
LanguageHaskell2010

Polysemy.Final.IO.Internal

Synopsis

Documentation

interpretFinalGlobal :: forall e a r. Member (Final IO) r => (forall x n. e n x -> Strategic IO n x) -> Sem (e ': r) a -> Sem r a Source #

Like interpretFinal specialized to IO, but also tries very hard to preserve state semantics dependant on the order interpreters are run, adressing the primary issue with Final.

Semantically, interpreters written using this behave very much as though they were written using withLowerToIO. However, this does not need to spawn an interpreter thread, making it more efficient (but not any more safe.)

interpretFinalGlobal operates under the assumption that any effectful state which can't be inspected using Inspector can't contain any values. For example, the effectful state for runError is Either e a. The inspector for this effectful state only fails if the effectful state is a Left value, which therefore doesn't contain any values of a.

The assumption holds true for all interpreters featured in polysemy, and is presumably always true for any properly implemented interpreter. interpretFinalGlobal may throw an exception if it is used together with an interpreter that uses weave improperly.

runViaFinalGlobal :: (Member (Final IO) r, Functor f) => MVar (f ()) -> (forall x. f (Sem r x) -> IO (f x)) -> (forall x. f x -> Maybe x) -> (forall x n. e n x -> Strategic IO n x) -> Sem (e ': r) a -> MaybeT IO a Source #