bluefin-0.0.6.0: The Bluefin effect system
Safe HaskellSafe-Inferred
LanguageHaskell2010

Bluefin.Jump

Synopsis

Documentation

Jump allows you to jump back to a previously-set location. A "jump" is equivalent to an untyped early return, or more precisely an early return of type (), which is itself an exception of type ().

Handle

type Jump = EarlyReturn () #

Handlers

withJump #

Arguments

:: forall (es :: Effects). (forall (j :: Effects). Jump j -> Eff (j :& es) ()) 
-> Eff es ()

͘

runPureEff $ withStateSource $ \source -> do
  n <- newState source 5
  total <- newState source 0

  withJump $ \done -> forever $ do
    n' <- get n
    modify total (+ n')
    when (n' == 0) $ jumpTo done
    modify n (subtract 1)

  get total
15

Effectful operations

jumpTo #

Arguments

:: forall (j :: Effects) (es :: Effects) a. j :> es 
=> Jump j 
-> Eff es a

͘

runPureEff $ withStateSource $ \source -> do
  n <- newState source 5
  total <- newState source 0

  withJump $ \done -> forever $ do
    n' <- get n
    modify total (+ n')
    when (n' == 0) $ jumpTo done
    modify n (subtract 1)

  get total
15