bluefin-0.6.0.0: The Bluefin effect system
Safe HaskellNone
LanguageHaskell2010

Bluefin.Jump

Description

This is an old interface and will be deprecated in the future. You are encouraged to use Bluefin.Capability.Jump instead.

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

Handlers

withJump Source #

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 Source #

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