-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/


-- | Monad transformer for evaluating to a fixpoint
--   
--   Monad transformer for evaluating to a fixpoint.
@package transformers-fix
@version 1.0


-- | 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 <tt>f</tt> on <tt>x</tt> until
--   <tt>f x == x</tt>.
--   
--   This might not be ideal for a few reasons: * <tt>x</tt> might not
--   implement <tt>Eq</tt>; * <tt>x</tt> might implement <tt>Eq</tt>, but
--   could contain floats of <tt>NaN</tt>, in which case <tt>NaN /=
--   NaN</tt>; or * checking equality can be expensive.
--   
--   Instead, this provides a function called <tt>progress</tt>, with the
--   same type as <tt>return</tt>, that marks the current transform as
--   having "made progress": that is, it should be re-run again. Then you
--   can provide <tt>fixpoint</tt> with a function of type <tt>a -&gt; FixT
--   _ a</tt>, which will be re-run until no progress is made.
module Control.Monad.Trans.Fix

-- | Fixpoint monad transformer.
newtype FixT m a
FixT :: m (a, Progress) -> FixT m a
[runFixT] :: FixT m a -> m (a, Progress)

-- | Have we made progress?
data Progress
RunAgain :: Progress
NoProgress :: Progress

-- | Apply the transform until it no longer makes progress
fixpoint :: Monad m => (a -> FixT m a) -> a -> m a

-- | Run a FixT once, regardless of whether it believes it makes progress
--   or not
once :: Monad m => FixT m a -> m a

-- | Take a function that returns <tt>Just</tt> on progress and
--   <tt>Nothing</tt> on completion.
fixOfMaybe :: Monad m => (a -> m (Maybe a)) -> a -> FixT m a

-- | Return a value and proclaim: "it might be worth running again"
progress :: Monad m => a -> FixT m a
instance GHC.Show.Show Control.Monad.Trans.Fix.Progress
instance GHC.Classes.Ord Control.Monad.Trans.Fix.Progress
instance GHC.Classes.Eq Control.Monad.Trans.Fix.Progress
instance GHC.Base.Monad m => GHC.Base.Monad (Control.Monad.Trans.Fix.FixT m)
instance GHC.Base.Monad m => GHC.Base.Functor (Control.Monad.Trans.Fix.FixT m)
instance GHC.Base.Monad m => GHC.Base.Applicative (Control.Monad.Trans.Fix.FixT m)
instance Control.Monad.Trans.Class.MonadTrans Control.Monad.Trans.Fix.FixT
