haskell / haskell/transformers
Proposal: ContT : add minimal usage example of delimited continuations
Open
- Dominant language
- Haskell
- Stars
- 5
- Forks
- 10
- Avg merge
- 2h 21m
- Merged PRs (30d)
- 1
Description
[original issue 80 by @ocramz]
Since shift/reset are not intuitive, I'd like to add at least one example to the ContT haddock, something along the lines of :
-- | demonstration of non-local control flow with a single shift/reset pair
--
-- λ> run t1
-- ('b',"b_a")
t1 :: ContT Char (State [Char]) Char
t1 = resetT $ do
let
x = 'a' -- input
cons w = lift $ modify (w :)
r <- shiftT $ \k -> do
cons x -- initial state uses the input
let x' = succ x -- compute a function of the input
y <- lift $ k x' -- delegate to the continuation k
cons y -- mutate state with the return value of k
pure x'
cons '_'
pure r
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.