Skip to content

athanclark/almost-fix

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

almost-fix

Combinators for predicative recursion

Usage

Simple Predicative Recursion

Say you want to perform f until some boolean test b:

almostFix b f

will run f until b returns False.

almostFix True f  ~  f . f . f ...

Monadic Predicates

Say you've got a monadic step f :: a -> m a, and some boolean test in the monad b :: m Bool - a good example of this would be in a MonadState Integer m stateful monad, and the monadic predicate liftM (< 5) get :: m Bool. Now, we bind until the predicate is falsified:

exclaimAgain :: MonadState Integer m => String -> m String
exclaimAgain a = do modify (+1)
                    return (a ++ "!")

exclaimFive :: String -> String
exclaimFive s = evalState (almostFix (liftM (<= 5) get) exclaimAgain s) 1

About

Combinators for predicative recursion

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published