bluefin-0.0.15.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 (e :: Effects). Jump e -> Eff (e :& 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 (e :: Effects) (es :: Effects) a. e :> es 
=> Jump e 
-> 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