https://github.com/juspay/purescript-backtrack
A monad transformer for handling backtrack in continuation based programs
https://github.com/juspay/purescript-backtrack
Last synced: 6 months ago
JSON representation
A monad transformer for handling backtrack in continuation based programs
- Host: GitHub
- URL: https://github.com/juspay/purescript-backtrack
- Owner: juspay
- Created: 2017-11-09T21:35:30.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2023-07-04T08:37:18.000Z (about 3 years ago)
- Last Synced: 2026-01-24T18:37:15.473Z (6 months ago)
- Language: PureScript
- Size: 13.7 KB
- Stars: 3
- Watchers: 13
- Forks: 8
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# purescript-backtrack
A monad transformer for implementing backtracking in continuation based program.
This library is purescript equivalent of Haskell library [`failback-monad`](http://haskell-web.blogspot.com/2012/03/failback-monad.html)
## Installation
```
bower install purescript-backtrack
```
## Example
```
main :: forall e. Eff (console::CONSOLE,random:: RANDOM|e) (FailBack Unit)
main = runBackT $ do
_ ← BackT $ pure <$> log "Starting Run"
a ← backpointRandomInt
_ ← BackT $ pure <$> log "Generated a number"
_ ← if (a >= 9) then pure unit else BackT (pure GoBack)
b ← backpointRandomInt
_ ← BackT $ pure <$> log "Generated another number"
_ ← if (b >= 9) then pure unit else BackT (pure GoBack)
BackT $ pure <$> logShow (a + b)
backpointRandomInt :: forall eff. BackT (Eff ( random :: RANDOM | eff)) Int
backpointRandomInt = BackT $ BackPoint <$> (randomInt 1 10)
```