Safe Haskell | Safe |
---|---|
Language | Haskell2010 |
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 implement Eq
;
* x
might implement Eq
, but could contain floats of NaN
, in which case NaN /= 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 provide fixpoint
with a function of type a -> FixT _ a
, which will be re-run
until no progress is made.
Documentation
Fixpoint monad transformer.
Have we made progress?
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