haskell / haskell/transformers

Proposal : ContT : minimal usage example of shift/reset

Open
#85 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Haskell
Stars
5
Forks
10
Avg merge
2h 21m
Merged PRs (30d)
1

Description

[original issue 81 by @ocramz]


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

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.