Safe Haskell | Safe |
---|---|
Language | Haskell2010 |
Control.Monad.Trans.Fix
Description
Monad transformer for evaluating to a fixpoint.
The idea is that some transforms need to be run multiple times.
Deciding whether to run a transform again can be somewhat tedious
though, as you cannot necessarily just run some transform f
on
x
until f x == x
.
This might not be ideal for a few reasons:
x
might not implementEq
;x
might implementEq
, but could contain floats ofNaN
, in which caseNaN /= NaN
; or- checking equality can be expensive.
Instead, this provides a function called progress
, with the same
type as return
, that marks the current transform as having "made
progress": that is, it should be re-run again. Then you can call
fixpoint
with a function of type a -> FixT m a
, which will be
re-run until no progress is made.
Documentation
Fixpoint monad transformer.
Have we made progress?
Constructors
RunAgain | |
NoProgress |
fixpoint :: Monad m => (a -> FixT m a) -> a -> m a Source #
Apply the transform until it no longer makes progress
once :: Monad m => FixT m a -> m a Source #
Run a FixT once, regardless of whether it believes it makes progress or not