Skip to content

Latest commit

 

History

History
30 lines (22 loc) · 918 Bytes

File metadata and controls

30 lines (22 loc) · 918 Bytes

purescript-backtrack

A monad transformer for implementing backtracking in continuation based program.

This library is purescript equivalent of Haskell library failback-monad

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)