concrete functor and monad transformers
#81Proposal : ContT : minimal usage example of shift/reset
Since delimited continuations are far from intuitive, I would like to add at least one usage example to their haddocks, something along these lines :
-- | demonstration of non-local control flow with a single shift/reset pair
--
-- λ> flip runState [] $ evalContT t1
-- (2,[2,0,1])
t1 :: ContT Int (State [Int]) Int
t1 = resetT $ do
let
x = 1 -- input
cons w = lift $ modify (w :)
r <- shiftT $ \k -> do
cons x -- initial state uses the input
let y = succ x -- compute a function of the input
z <- lift $ k y -- delegate to the continuation k
cons z -- mutate state with the return value of k
pure y
cons 0
pure r