polysemy-1.1.0.0: Higher-order, low-boilerplate, zero-cost free monads.

Safe HaskellNone
LanguageHaskell2010

Polysemy.Fixpoint

Contents

Synopsis

Effect

data Fixpoint m a where Source #

An effect for providing mfix.

Constructors

Fixpoint :: (a -> m a) -> Fixpoint m a 

Interpretations

runFixpoint :: (forall x. Sem r x -> x) -> Sem (Fixpoint ': r) a -> Sem r a Source #

Run a Fixpoint effect purely.

Note: This is subject to the same traps as MonadFix instances for monads with failure: this will throw an exception if you try to recursively use the result of a failed computation in an action whose effect may be observed even though the computation failed.

For example, the following program will throw an exception upon evaluating the final state: bad :: (Int, Either () Int) bad = run . runFixpoint run . runLazyState Int 1 . runError $ mdo put a a <- throw () return a @

runFixpoint also operates under the assumption that any effectful state which can't be inspected using Inspector can't contain any values. This is true for all interpreters featured in this package, and is presumably always true for any properly implemented interpreter. runFixpoint may throw an exception if it is used together with an interpreter that uses weave improperly.

If runFixpoint throws an exception for you, and it can't be due to any of the above, then open an issue over at the GitHub repository for polysemy.

runFixpointM :: (MonadFix m, Member (Embed m) r) => (forall x. Sem r x -> m x) -> Sem (Fixpoint ': r) a -> Sem r a Source #

Run a Fixpoint effect in terms of an underlying MonadFix instance.

Note: runFixpointM is subject to the same caveats as runFixpoint.