Proposal: ContT : add minimal usage example of delimited continuations

Open Beginner friendly
#21 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
65/100
Issue type
Documentation
Clarity
Clearly specified
Activity status
Quiet
Tech stack
haskell
Domain
documentation

Research direction

Start at the ContT Haddock documentation and review how shiftT and resetT are currently explained. Add the proposed minimal usage example, preserving its demonstration of non-local control flow, and confirm that the documented result makes the single shift/reset pair understandable.

Written by the indexing model from the issue text.

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&#39; = succ x -- compute a function of the input
    y <- lift $ k x&#39; -- delegate to the continuation k
    cons y -- mutate state with the return value of k
    pure x&#39;
  cons &#39;_&#39;
  pure r
Dominant language
Haskell
Stars
5
Forks
10
Avg merge
2h 21m
Merged PRs (30d)
1

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from haskell/transformers

All issues in haskell/transformers

Similar issues

More Haskell issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.