https://github.com/athanclark/almost-fix
Combinators for predicative recursion
https://github.com/athanclark/almost-fix
fixpoint haskell predicates
Last synced: 10 months ago
JSON representation
Combinators for predicative recursion
- Host: GitHub
- URL: https://github.com/athanclark/almost-fix
- Owner: athanclark
- License: bsd-3-clause
- Created: 2015-07-24T01:28:47.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2015-07-24T06:48:21.000Z (almost 11 years ago)
- Last Synced: 2025-05-20T01:14:07.129Z (about 1 year ago)
- Topics: fixpoint, haskell, predicates
- Language: Haskell
- Size: 113 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
almost-fix
==========
Combinators for predicative recursion
## Usage
### Simple Predicative Recursion
Say you want to perform `f` until some boolean test `b`:
```haskell
almostFix b f
```
will run `f` until `b` returns `False`.
```haskell
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:
```haskell
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
```