Skip to content

Proposal: ContT : add minimal usage example of delimited continuations #21

Description

@sjshuck

[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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions