Commits

Austin Seipp committed fa71857

Updated documentation.

Signed-off-by: Austin Seipp <mad.one@gmail.com>

  • Participants
  • Parent commits 5119c58
  • Branches gh-pages

Comments (0)

Files changed (6)

File doc/Control-Delimited-Tutorial.html

 window.onload = function () {pageLoad();setSynopsis("mini_Control-Delimited-Tutorial.html");};
 //]]>
 </script></head><body><div id="package-header"><ul class="links" id="page-menu"><li><a href="src/Control-Delimited-Tutorial.html">Source</a></li><li><a href="index.html">Contents</a></li><li><a href="doc-index.html">Index</a></li></ul><p class="caption">asai-0.0.0.0: A minimal library for delimited continuations.</p></div><div id="content"><div id="module-header"><table class="info"><tr><th>Portability</th><td>portable</td></tr><tr><th>Stability</th><td>experimental</td></tr><tr><th>Maintainer</th><td>mad.one@gmail.com</td></tr><tr><th>Safe Haskell</th><td>Safe-Inferred</td></tr></table><p class="caption">Control.Delimited.Tutorial</p></div><div id="table-of-contents"><p class="caption">Contents</p><ul><li><a href="#g:1">Introduction
-</a></li><li><a href="#g:2">Using <code>do</code>-notation
-</a></li><li><a href="#g:3">Other notes
-</a></li><li><a href="#g:4">References
+</a></li><li><a href="#g:2">Delimited continuations
+</a><ul><li><a href="#g:3">Part 1
+</a></li><li><a href="#g:4">Part 2
+</a></li></ul></li><li><a href="#g:5">Using <code>do</code>-notation
+</a></li><li><a href="#g:6">Other notes
+</a></li><li><a href="#g:7">References
 </a></li></ul></div><div id="description"><p class="caption">Description</p><div class="doc"><p>This module provides a brief introductory tutorial in the
  &quot;Introduction&quot; section, followed by some discussion behind the
  theory of the library with references.
 </p></div></div><div id="synopsis"><p id="control.syn" class="caption expander" onclick="toggleSection('syn')">Synopsis</p><ul id="section.syn" class="hide" onclick="toggleSection('syn')"></ul></div><div id="interface"><h1 id="g:1">Introduction
+</h1><div class="doc"><p>Continuations are a well known abstraction for 'picking up where you
+left off.' When you use <code>call/cc</code> traditionally in something like
+scheme, you pass it a function <code>f</code> which receives a function <code>k</code>, and
+when <code>k</code> is invoked you 'call the continuation' and return where
+<code>call/cc</code> left off. In this sense, <code>k</code> is a reification of the state
+you were in when you invoked <code>f</code>.
+</p><p>But <code>call/cc</code> is, as some say, 'overrated.' For one, it is not
+possible to return a value from the continuation; you merely pick up
+where you left off. By fixing this we get delimited continuations: an
+abstraction that allows us to slice up a continuation and compose
+them. But at this point, we suffer in a statically typed language due
+to the fact that the type of the continuation is fixed, and cannot
+vary.
+</p><p>In the same way that continuations form a monad, so do delimited
+continuations in their composition. This package provides a delimited
+continuation monad which implements truly polymorphic <code>shift</code> and
+<code>reset</code> operators, via <em>answer type polymorphism</em>, which allows the
+results of a delimited computation to vary.
+</p><p>This implementation (using parameterized monads) was first implemented
+by - and this package derived from - Oleg Kiselyov [1]. It directly
+implements the typing rules of Kenichi Asai's lambda/shift calculus
+[2], featuring answer type polymorphism.
+</p><p>A general tutorial on delimited continuations in OchaCaml (with code
+in Haskell and OCaml) from Asai/Kiselyov is available [3].
+</p></div><h1 id="g:2">Delimited continuations
 </h1><div class="doc"><p>Lorem ipsum...
-</p><pre class="screen"><code class="prompt">&gt;&gt;&gt; </code><strong class="userinput"><code>runDelim $ reset $ (shift1 (\_ -&gt; return &quot;hello&quot;) &gt;&gt;= \r -&gt; return (r + 1))
+</p></div><h2 id="g:3">Part 1
+</h2><div class="doc"><p>Lorem ipsum...
+</p><pre class="screen"><code class="prompt">&gt;&gt;&gt; </code><strong class="userinput"><code>runDelim $ reset $ shift1 (\_ -&gt; ret &quot;hello&quot;) !&gt;&gt;= \r -&gt; ret (r + 1)
 </code></strong>&quot;hello&quot;
-</pre></div><h1 id="g:2">Using <code>do</code>-notation
+</pre></div><h2 id="g:4">Part 2
+</h2><div class="doc"><p>Lorem ipsum...
+</p><pre class="screen"><code class="prompt">&gt;&gt;&gt; </code><strong class="userinput"><code>runDelim $ reset $ shift1 (\_ -&gt; return &quot;hello&quot;) &gt;&gt;= \r -&gt; return (r + 1)
+</code></strong>&quot;hello&quot;
+</pre></div><h1 id="g:5">Using <code>do</code>-notation
 </h1><div class="doc"><p>It's possible to use GHC's <code>RebindableSyntax</code> extension to re-define
 <code>do</code> notation to use the <code><a href="Control-Indexed-Monad.html#t:Monad-39-">Monad'</a></code> type class.
 </p><p>Begin your module by hiding the regular <code><a href="/usr/local/share/doc/ghc/html/libraries/base-4.6.0.0/Control-Monad.html#t:Monad">Monad</a></code> methods, and then
  --   reset (fun () -&gt; 1 + shift (fun _ -&gt; &quot;hello&quot;)) ;;
 </pre><p>See <code>examples/Simple.hs</code> (included in the distribution) for several
 more examples.
-</p></div><h1 id="g:3">Other notes
+</p></div><h1 id="g:6">Other notes
 </h1><div class="doc"><p>This package requires GHC's <code>RankNTypes</code> extension, as it uses it for
 the definition of <code><a href="Control-Delimited.html#v:shift2">shift2</a></code>. The original
 implementation by Kiselyov is Haskell98. You do not need to enable
 <code>RankNTypes</code> to use this package.
-</p></div><h1 id="g:4">References
-</h1><div class="doc"><ul><li> <em>Polymorphic Delimited Continuations</em>, by Asai, Kameyama in <em>APLAS '07</em>:
-    <a href="http://logic.cs.tsukuba.ac.jp/~kam/paper/aplas07.pdf">http://logic.cs.tsukuba.ac.jp/~kam/paper/aplas07.pdf</a>
-</li><li> <em>Genuine shift\reset in Haskell98</em>, by Kiselyov, on <em>haskell-cafe</em>:
-    <a href="http://okmij.org/ftp/continuations/implementations.html#genuine-shift">http://okmij.org/ftp/continuations/implementations.html#genuine-shift</a>
+</p></div><h1 id="g:7">References
+</h1><div class="doc"><ol><li> <em>Genuine shift\reset in Haskell98</em>, by Kiselyov, on <em>haskell-cafe</em>:
+     <a href="http://okmij.org/ftp/continuations/implementations.html#genuine-shift">http://okmij.org/ftp/continuations/implementations.html#genuine-shift</a>
+</li><li> <em>Polymorphic Delimited Continuations</em>, by Asai, Kameyama in <em>APLAS '07</em>:
+     <a href="http://logic.cs.tsukuba.ac.jp/~kam/paper/aplas07.pdf">http://logic.cs.tsukuba.ac.jp/~kam/paper/aplas07.pdf</a>
 </li><li> <em>Introduction to programming with shift and reset</em>, by Kiselyov, Asai, in <em>CW2011</em>:
-    <a href="http://okmij.org/ftp/continuations/index.html#tutorial">http://okmij.org/ftp/continuations/index.html#tutorial</a>
-</li></ul></div></div></div><div id="footer"><p>Produced by <a href="http://www.haskell.org/haddock/">Haddock</a> version 2.13.1</p></div></body></html>
+      <a href="http://okmij.org/ftp/continuations/index.html#tutorial">http://okmij.org/ftp/continuations/index.html#tutorial</a>
+</li></ol></div></div></div><div id="footer"><p>Produced by <a href="http://www.haskell.org/haddock/">Haddock</a> version 2.13.1</p></div></body></html>

File doc/Control-Delimited.html

 </p><p>Functions of type <code>a -&gt; <code><a href="Control-Delimited.html#t:Delim">Delim</a></code> s t b</code> can be thought of as
  functions of type <code>a / s -&gt; b / t</code>, which means given an <code>a</code> we
  return a <code>b</code>, changing the <em>answer type</em> of the continuation from
- <code>s</code> to <code>t</code>.
+ <code>s</code> to <code>t</code>. The take away from this is that the <code>s</code> and <code>t</code>
+ variables representing the input and output answer type,
+ respectively.
 </p><p>If a <code><a href="Control-Delimited.html#t:Delim">Delim</a></code> does not capture the computation using one of the
  various <code>shift</code> operators (or <code>shift</code> does not change the answer
  type,) then the term is <em>polymorphic</em> in the answer type.
  polymorphic (in this case, the answer type of the enclosing <code><a href="Control-Delimited.html#v:reset">reset</a></code>
  is <code><a href="/usr/local/share/doc/ghc/html/libraries/base-4.6.0.0/Data-Int.html#t:Int">Int</a></code>.)
 </p></div><div class="subs instances"><p id="control.i:Delim" class="caption collapser" onclick="toggleSection('i:Delim')">Instances</p><div id="section.i:Delim" class="show"><table><tr><td class="src"><a href="Control-Indexed-Monad.html#t:Monad-39-">Monad'</a> <a href="Control-Delimited.html#t:Delim">Delim</a></td><td class="doc"><p>Delimited continuations form a parameterized <code><a href="Control-Indexed-Monad.html#t:Monad-39-">Monad'</a></code>.
-</p></td></tr></table></div></div></div><div class="top"><p class="src"><a name="v:reset" class="def">reset</a> ::  <a href="Control-Delimited.html#t:Delim">Delim</a> s t s -&gt; <a href="Control-Delimited.html#t:Delim">Delim</a> s' s' t<a href="src/Control-Delimited.html#reset" class="link">Source</a></p><div class="doc"><p>Delimit a computation.
+</p></td></tr></table></div></div></div><div class="top"><p class="src"><a name="v:reset" class="def">reset</a> ::  <a href="Control-Delimited.html#t:Delim">Delim</a> s t s -&gt; <a href="Control-Delimited.html#t:Delim">Delim</a> s' s' t<a href="src/Control-Delimited.html#reset" class="link">Source</a></p><div class="doc"><p>Delimit a computation. The type variable <code>s'</code> indicates that
+ <code><a href="Control-Delimited.html#v:reset">reset</a></code> is polymorphic in its answer type.
 </p></div></div><h2 id="g:2">A family of shift operators
 </h2><div class="top"><p class="src"><a name="v:shift0" class="def">shift0</a> ::  ((b -&gt; s) -&gt; t) -&gt; <a href="Control-Delimited.html#t:Delim">Delim</a> s t b<a href="src/Control-Delimited.html#shift0" class="link">Source</a></p><div class="doc"><p>Clear the current continuation and invoke our handler with it
  bound as a parameter.

File doc/asai.haddock

Binary file modified.

File doc/mini_Control-Delimited-Tutorial.html

 window.onload = function () {pageLoad();};
 //]]>
 </script></head><body id="mini"><div id="module-header"><p class="caption">Control.Delimited.Tutorial</p></div><div id="interface"><h1>Introduction
-</h1><h1>Using <code>do</code>-notation
+</h1><h1>Delimited continuations
+</h1><h2>Part 1
+</h2><h2>Part 2
+</h2><h1>Using <code>do</code>-notation
 </h1><h1>Other notes
 </h1><h1>References
 </h1></div></body></html>

File doc/src/Control-Delimited-Tutorial.html

 <a name="line-17"></a>       <span class='hs-layout'>(</span> <span class='hs-comment'>-- * Introduction</span>
 <a name="line-18"></a>         <span class='hs-comment'>-- $intro</span>
 <a name="line-19"></a>
-<a name="line-20"></a>         <span class='hs-comment'>-- * Using @do@-notation</span>
-<a name="line-21"></a>         <span class='hs-comment'>-- $donotation</span>
+<a name="line-20"></a>         <span class='hs-comment'>-- * Delimited continuations</span>
+<a name="line-21"></a>         <span class='hs-comment'>-- $delimcc</span>
 <a name="line-22"></a>
-<a name="line-23"></a>         <span class='hs-comment'>-- * Other notes</span>
-<a name="line-24"></a>         <span class='hs-comment'>-- $othernotes</span>
+<a name="line-23"></a>         <span class='hs-comment'>-- ** Part 1</span>
+<a name="line-24"></a>         <span class='hs-comment'>-- $pt1</span>
 <a name="line-25"></a>
-<a name="line-26"></a>         <span class='hs-comment'>-- * References</span>
-<a name="line-27"></a>         <span class='hs-comment'>-- $refs</span>
-<a name="line-28"></a>       <span class='hs-layout'>)</span> <span class='hs-keyword'>where</span>
-<a name="line-29"></a><span class='hs-keyword'>import</span> <span class='hs-conid'>Prelude</span> <span class='hs-varid'>hiding</span> <span class='hs-layout'>(</span><span class='hs-varid'>return</span><span class='hs-layout'>,</span> <span class='hs-varid'>fail</span><span class='hs-layout'>,</span> <span class='hs-layout'>(</span><span class='hs-varop'>&gt;&gt;=</span><span class='hs-layout'>)</span><span class='hs-layout'>,</span> <span class='hs-layout'>(</span><span class='hs-varop'>=&lt;&lt;</span><span class='hs-layout'>)</span><span class='hs-layout'>)</span>
-<a name="line-30"></a><span class='hs-keyword'>import</span> <span class='hs-conid'>Control</span><span class='hs-varop'>.</span><span class='hs-conid'>Delimited</span>
+<a name="line-26"></a>         <span class='hs-comment'>-- ** Part 2</span>
+<a name="line-27"></a>         <span class='hs-comment'>-- $pt2</span>
+<a name="line-28"></a>
+<a name="line-29"></a>         <span class='hs-comment'>-- * Using @do@-notation</span>
+<a name="line-30"></a>         <span class='hs-comment'>-- $donotation</span>
 <a name="line-31"></a>
-<a name="line-32"></a><span class='hs-comment'>--</span>
-<a name="line-33"></a><span class='hs-comment'>-- Aspects of RebindableSyntax</span>
-<a name="line-34"></a><span class='hs-comment'>--</span>
-<a name="line-35"></a>
-<a name="line-36"></a><a name="%3e%3e="></a><span class='hs-definition'>m</span> <span class='hs-varop'>&gt;&gt;=</span> <span class='hs-varid'>f</span>  <span class='hs-keyglyph'>=</span> <span class='hs-varid'>m</span> <span class='hs-varop'>!&gt;&gt;=</span> <span class='hs-varid'>f</span>
-<a name="line-37"></a><a name="return"></a><span class='hs-definition'>return</span> <span class='hs-varid'>x</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>ret</span> <span class='hs-varid'>x</span>
-<a name="line-38"></a><a name="fail"></a><span class='hs-definition'>fail</span> <span class='hs-varid'>x</span>   <span class='hs-keyglyph'>=</span> <span class='hs-varid'>error</span> <span class='hs-varid'>x</span>
-<a name="line-39"></a><a name="=%3c%3c"></a><span class='hs-definition'>f</span> <span class='hs-varop'>=&lt;&lt;</span> <span class='hs-varid'>m</span>  <span class='hs-keyglyph'>=</span> <span class='hs-varid'>m</span> <span class='hs-varop'>!&gt;&gt;=</span> <span class='hs-varid'>f</span>
+<a name="line-32"></a>         <span class='hs-comment'>-- * Other notes</span>
+<a name="line-33"></a>         <span class='hs-comment'>-- $othernotes</span>
+<a name="line-34"></a>
+<a name="line-35"></a>         <span class='hs-comment'>-- * References</span>
+<a name="line-36"></a>         <span class='hs-comment'>-- $refs</span>
+<a name="line-37"></a>       <span class='hs-layout'>)</span> <span class='hs-keyword'>where</span>
+<a name="line-38"></a><span class='hs-keyword'>import</span> <span class='hs-conid'>Prelude</span> <span class='hs-varid'>hiding</span> <span class='hs-layout'>(</span><span class='hs-varid'>return</span><span class='hs-layout'>,</span> <span class='hs-varid'>fail</span><span class='hs-layout'>,</span> <span class='hs-layout'>(</span><span class='hs-varop'>&gt;&gt;=</span><span class='hs-layout'>)</span><span class='hs-layout'>,</span> <span class='hs-layout'>(</span><span class='hs-varop'>=&lt;&lt;</span><span class='hs-layout'>)</span><span class='hs-layout'>)</span>
+<a name="line-39"></a><span class='hs-keyword'>import</span> <span class='hs-conid'>Control</span><span class='hs-varop'>.</span><span class='hs-conid'>Delimited</span>
 <a name="line-40"></a>
-<a name="line-41"></a><span class='hs-comment'>{- $intro
-<a name="line-42"></a>
-<a name="line-43"></a>Lorem ipsum...
+<a name="line-41"></a><span class='hs-comment'>--</span>
+<a name="line-42"></a><span class='hs-comment'>-- Aspects of RebindableSyntax</span>
+<a name="line-43"></a><span class='hs-comment'>--</span>
 <a name="line-44"></a>
-<a name="line-45"></a>&gt;&gt;&gt; runDelim $ reset $ (shift1 (\_ -&gt; return "hello") &gt;&gt;= \r -&gt; return (r + 1))
-<a name="line-46"></a>"hello"
-<a name="line-47"></a>
-<a name="line-48"></a>-}</span>
+<a name="line-45"></a><a name="%3e%3e="></a><span class='hs-definition'>m</span> <span class='hs-varop'>&gt;&gt;=</span> <span class='hs-varid'>f</span>  <span class='hs-keyglyph'>=</span> <span class='hs-varid'>m</span> <span class='hs-varop'>!&gt;&gt;=</span> <span class='hs-varid'>f</span>
+<a name="line-46"></a><a name="return"></a><span class='hs-definition'>return</span> <span class='hs-varid'>x</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>ret</span> <span class='hs-varid'>x</span>
+<a name="line-47"></a><a name="fail"></a><span class='hs-definition'>fail</span> <span class='hs-varid'>x</span>   <span class='hs-keyglyph'>=</span> <span class='hs-varid'>error</span> <span class='hs-varid'>x</span>
+<a name="line-48"></a><a name="=%3c%3c"></a><span class='hs-definition'>f</span> <span class='hs-varop'>=&lt;&lt;</span> <span class='hs-varid'>m</span>  <span class='hs-keyglyph'>=</span> <span class='hs-varid'>m</span> <span class='hs-varop'>!&gt;&gt;=</span> <span class='hs-varid'>f</span>
 <a name="line-49"></a>
-<a name="line-50"></a><span class='hs-comment'>{- $donotation
+<a name="line-50"></a><span class='hs-comment'>{- $intro
 <a name="line-51"></a>
-<a name="line-52"></a>It's possible to use GHC's @RebindableSyntax@ extension to re-define
-<a name="line-53"></a>@do@ notation to use the 'Monad'' type class.
-<a name="line-54"></a>
-<a name="line-55"></a>Begin your module by hiding the regular 'Monad' methods, and then
-<a name="line-56"></a>redefine 'Prelude.&gt;&gt;=' and 'Prelude.return'. Feel free to redefine
-<a name="line-57"></a>other operators too. Here's an example (you'll need to fix the
-<a name="line-58"></a>@LANGUAGE@ pragma yourself on the first line, since Haddock eats it
-<a name="line-59"></a>otherwise):
-<a name="line-60"></a>
-<a name="line-61"></a>&gt; [-# LANGUAGE RebindableSyntax #-]
-<a name="line-62"></a>&gt; module Foo where
-<a name="line-63"></a>&gt; import Prelude hiding (return, fail, (&gt;&gt;=), (=&lt;&lt;), (&gt;&gt;))
-<a name="line-64"></a>&gt; import Control.Delimited
-<a name="line-65"></a>&gt;
-<a name="line-66"></a>&gt; -- Aspects of RebindableSyntax
-<a name="line-67"></a>&gt; return x = ret x
-<a name="line-68"></a>&gt; fail s   = error s
-<a name="line-69"></a>&gt; m &gt;&gt;= f  = m !&gt;&gt;= f
-<a name="line-70"></a>&gt; f =&lt;&lt; m  = m !&gt;&gt;= f
-<a name="line-71"></a>&gt; f &gt;&gt; k   = m !&gt;&gt;= \_ -&gt; k
-<a name="line-72"></a>&gt;
-<a name="line-73"></a>&gt; -- Now use 'do' notation instead of the indexed bind/return
-<a name="line-74"></a>&gt; -- functions.
-<a name="line-75"></a>&gt;
-<a name="line-76"></a>&gt; -- You can lift regular monads into parameterized monads using
-<a name="line-77"></a>&gt; -- 'lift' and 'runI'
-<a name="line-78"></a>&gt; io1 :: IO ()
-<a name="line-79"></a>&gt; io1 = runI $ do
-<a name="line-80"></a>&gt;   lift $ putStrLn "hi!"
-<a name="line-81"></a>&gt;   lift $ putStrLn "hi!"
-<a name="line-82"></a>&gt;   return ()
-<a name="line-83"></a>&gt;
-<a name="line-84"></a>&gt; test1 :: String
-<a name="line-85"></a>&gt; test1 = runDelim $ reset $ do
-<a name="line-86"></a>&gt;   r &lt;- shift1 (\_ -&gt; return "hello")
-<a name="line-87"></a>&gt;   return (r + 1)
-<a name="line-88"></a>&gt; -- This is equivalent to the OchaCaml term:
-<a name="line-89"></a>&gt; --   reset (fun () -&gt; 1 + shift (fun _ -&gt; "hello")) ;;
+<a name="line-52"></a>Continuations are a well known abstraction for 'picking up where you
+<a name="line-53"></a>left off.' When you use @call/cc@ traditionally in something like
+<a name="line-54"></a>scheme, you pass it a function @f@ which receives a function @k@, and
+<a name="line-55"></a>when @k@ is invoked you 'call the continuation' and return where
+<a name="line-56"></a>@call/cc@ left off. In this sense, @k@ is a reification of the state
+<a name="line-57"></a>you were in when you invoked @f@.
+<a name="line-58"></a>
+<a name="line-59"></a>But @call/cc@ is, as some say, 'overrated.' For one, it is not
+<a name="line-60"></a>possible to return a value from the continuation; you merely pick up
+<a name="line-61"></a>where you left off. By fixing this we get delimited continuations: an
+<a name="line-62"></a>abstraction that allows us to slice up a continuation and compose
+<a name="line-63"></a>them. But at this point, we suffer in a statically typed language due
+<a name="line-64"></a>to the fact that the type of the continuation is fixed, and cannot
+<a name="line-65"></a>vary.
+<a name="line-66"></a>
+<a name="line-67"></a>In the same way that continuations form a monad, so do delimited
+<a name="line-68"></a>continuations in their composition. This package provides a delimited
+<a name="line-69"></a>continuation monad which implements truly polymorphic @shift@ and
+<a name="line-70"></a>@reset@ operators, via /answer type polymorphism/, which allows the
+<a name="line-71"></a>results of a delimited computation to vary.
+<a name="line-72"></a>
+<a name="line-73"></a>This implementation (using parameterized monads) was first implemented
+<a name="line-74"></a>by - and this package derived from - Oleg Kiselyov [1]. It directly
+<a name="line-75"></a>implements the typing rules of Kenichi Asai's lambda/shift calculus
+<a name="line-76"></a>[2], featuring answer type polymorphism.
+<a name="line-77"></a>
+<a name="line-78"></a>A general tutorial on delimited continuations in OchaCaml (with code
+<a name="line-79"></a>in Haskell and OCaml) from Asai/Kiselyov is available [3].
+<a name="line-80"></a>
+<a name="line-81"></a>-}</span>
+<a name="line-82"></a>
+<a name="line-83"></a><span class='hs-comment'>{- $delimcc
+<a name="line-84"></a>
+<a name="line-85"></a>Lorem ipsum...
+<a name="line-86"></a>
+<a name="line-87"></a>-}</span>
+<a name="line-88"></a>
+<a name="line-89"></a><span class='hs-comment'>{- $pt1
 <a name="line-90"></a>
-<a name="line-91"></a>See @examples/Simple.hs@ (included in the distribution) for several
-<a name="line-92"></a>more examples.
-<a name="line-93"></a>
-<a name="line-94"></a>-}</span>
+<a name="line-91"></a>Lorem ipsum...
+<a name="line-92"></a>
+<a name="line-93"></a>&gt;&gt;&gt; runDelim $ reset $ shift1 (\_ -&gt; ret "hello") !&gt;&gt;= \r -&gt; ret (r + 1)
+<a name="line-94"></a>"hello"
 <a name="line-95"></a>
-<a name="line-96"></a><span class='hs-comment'>{- $othernotes
+<a name="line-96"></a>-}</span>
 <a name="line-97"></a>
-<a name="line-98"></a>This package requires GHC's @RankNTypes@ extension, as it uses it for
-<a name="line-99"></a>the definition of 'Control.Delimited.shift2'. The original
-<a name="line-100"></a>implementation by Kiselyov is Haskell98. You do not need to enable
-<a name="line-101"></a>@RankNTypes@ to use this package.
-<a name="line-102"></a>
-<a name="line-103"></a>-}</span>
+<a name="line-98"></a><span class='hs-comment'>{- $pt2
+<a name="line-99"></a>
+<a name="line-100"></a>Lorem ipsum...
+<a name="line-101"></a>
+<a name="line-102"></a>&gt;&gt;&gt; runDelim $ reset $ shift1 (\_ -&gt; return "hello") &gt;&gt;= \r -&gt; return (r + 1)
+<a name="line-103"></a>"hello"
 <a name="line-104"></a>
-<a name="line-105"></a><span class='hs-comment'>{- $refs
+<a name="line-105"></a>-}</span>
 <a name="line-106"></a>
-<a name="line-107"></a>  * /Polymorphic Delimited Continuations/, by Asai, Kameyama in /APLAS '07/:
-<a name="line-108"></a>    &lt;<a href="http://logic.cs.tsukuba.ac.jp/~kam/paper/aplas07.pdf">http://logic.cs.tsukuba.ac.jp/~kam/paper/aplas07.pdf</a>&gt;
-<a name="line-109"></a>
-<a name="line-110"></a>  * /Genuine shift\reset in Haskell98/, by Kiselyov, on /haskell-cafe/:
-<a name="line-111"></a>    &lt;<a href="http://okmij.org/ftp/continuations/implementations.html#genuine-shift">http://okmij.org/ftp/continuations/implementations.html#genuine-shift</a>&gt;
-<a name="line-112"></a>
-<a name="line-113"></a>  * /Introduction to programming with shift and reset/, by Kiselyov, Asai, in /CW2011/:
-<a name="line-114"></a>    &lt;<a href="http://okmij.org/ftp/continuations/index.html#tutorial">http://okmij.org/ftp/continuations/index.html#tutorial</a>&gt;
-<a name="line-115"></a>
-<a name="line-116"></a>-}</span>
+<a name="line-107"></a><span class='hs-comment'>{- $donotation
+<a name="line-108"></a>
+<a name="line-109"></a>It's possible to use GHC's @RebindableSyntax@ extension to re-define
+<a name="line-110"></a>@do@ notation to use the 'Monad'' type class.
+<a name="line-111"></a>
+<a name="line-112"></a>Begin your module by hiding the regular 'Monad' methods, and then
+<a name="line-113"></a>redefine 'Prelude.&gt;&gt;=' and 'Prelude.return'. Feel free to redefine
+<a name="line-114"></a>other operators too. Here's an example (you'll need to fix the
+<a name="line-115"></a>@LANGUAGE@ pragma yourself on the first line, since Haddock eats it
+<a name="line-116"></a>otherwise):
+<a name="line-117"></a>
+<a name="line-118"></a>&gt; [-# LANGUAGE RebindableSyntax #-]
+<a name="line-119"></a>&gt; module Foo where
+<a name="line-120"></a>&gt; import Prelude hiding (return, fail, (&gt;&gt;=), (=&lt;&lt;), (&gt;&gt;))
+<a name="line-121"></a>&gt; import Control.Delimited
+<a name="line-122"></a>&gt;
+<a name="line-123"></a>&gt; -- Aspects of RebindableSyntax
+<a name="line-124"></a>&gt; return x = ret x
+<a name="line-125"></a>&gt; fail s   = error s
+<a name="line-126"></a>&gt; m &gt;&gt;= f  = m !&gt;&gt;= f
+<a name="line-127"></a>&gt; f =&lt;&lt; m  = m !&gt;&gt;= f
+<a name="line-128"></a>&gt; f &gt;&gt; k   = m !&gt;&gt;= \_ -&gt; k
+<a name="line-129"></a>&gt;
+<a name="line-130"></a>&gt; -- Now use 'do' notation instead of the indexed bind/return
+<a name="line-131"></a>&gt; -- functions.
+<a name="line-132"></a>&gt;
+<a name="line-133"></a>&gt; -- You can lift regular monads into parameterized monads using
+<a name="line-134"></a>&gt; -- 'lift' and 'runI'
+<a name="line-135"></a>&gt; io1 :: IO ()
+<a name="line-136"></a>&gt; io1 = runI $ do
+<a name="line-137"></a>&gt;   lift $ putStrLn "hi!"
+<a name="line-138"></a>&gt;   lift $ putStrLn "hi!"
+<a name="line-139"></a>&gt;   return ()
+<a name="line-140"></a>&gt;
+<a name="line-141"></a>&gt; test1 :: String
+<a name="line-142"></a>&gt; test1 = runDelim $ reset $ do
+<a name="line-143"></a>&gt;   r &lt;- shift1 (\_ -&gt; return "hello")
+<a name="line-144"></a>&gt;   return (r + 1)
+<a name="line-145"></a>&gt; -- This is equivalent to the OchaCaml term:
+<a name="line-146"></a>&gt; --   reset (fun () -&gt; 1 + shift (fun _ -&gt; "hello")) ;;
+<a name="line-147"></a>
+<a name="line-148"></a>See @examples/Simple.hs@ (included in the distribution) for several
+<a name="line-149"></a>more examples.
+<a name="line-150"></a>
+<a name="line-151"></a>-}</span>
+<a name="line-152"></a>
+<a name="line-153"></a><span class='hs-comment'>{- $othernotes
+<a name="line-154"></a>
+<a name="line-155"></a>This package requires GHC's @RankNTypes@ extension, as it uses it for
+<a name="line-156"></a>the definition of 'Control.Delimited.shift2'. The original
+<a name="line-157"></a>implementation by Kiselyov is Haskell98. You do not need to enable
+<a name="line-158"></a>@RankNTypes@ to use this package.
+<a name="line-159"></a>
+<a name="line-160"></a>-}</span>
+<a name="line-161"></a>
+<a name="line-162"></a><span class='hs-comment'>{- $refs
+<a name="line-163"></a>
+<a name="line-164"></a>  1. /Genuine shift\reset in Haskell98/, by Kiselyov, on /haskell-cafe/:
+<a name="line-165"></a>     &lt;<a href="http://okmij.org/ftp/continuations/implementations.html#genuine-shift">http://okmij.org/ftp/continuations/implementations.html#genuine-shift</a>&gt;
+<a name="line-166"></a>
+<a name="line-167"></a>  2. /Polymorphic Delimited Continuations/, by Asai, Kameyama in /APLAS '07/:
+<a name="line-168"></a>     &lt;<a href="http://logic.cs.tsukuba.ac.jp/~kam/paper/aplas07.pdf">http://logic.cs.tsukuba.ac.jp/~kam/paper/aplas07.pdf</a>&gt;
+<a name="line-169"></a>
+<a name="line-170"></a>  3. /Introduction to programming with shift and reset/, by Kiselyov, Asai, in /CW2011/:
+<a name="line-171"></a>      &lt;<a href="http://okmij.org/ftp/continuations/index.html#tutorial">http://okmij.org/ftp/continuations/index.html#tutorial</a>&gt;
+<a name="line-172"></a>
+<a name="line-173"></a>-}</span>
 </pre></body>
 </html>

File doc/src/Control-Delimited.html

 <a name="line-37"></a><a name="Delim"></a><span class='hs-comment'>-- Functions of type @a -&gt; 'Delim' s t b@ can be thought of as</span>
 <a name="line-38"></a><a name="Delim"></a><span class='hs-comment'>-- functions of type @a \/ s -&gt; b \/ t@, which means given an @a@ we</span>
 <a name="line-39"></a><a name="Delim"></a><span class='hs-comment'>-- return a @b@, changing the /answer type/ of the continuation from</span>
-<a name="line-40"></a><a name="Delim"></a><span class='hs-comment'>-- @s@ to @t@.</span>
-<a name="line-41"></a><a name="Delim"></a><span class='hs-comment'>--</span>
-<a name="line-42"></a><a name="Delim"></a><span class='hs-comment'>-- If a 'Delim' does not capture the computation using one of the</span>
-<a name="line-43"></a><a name="Delim"></a><span class='hs-comment'>-- various @shift@ operators (or @shift@ does not change the answer</span>
-<a name="line-44"></a><a name="Delim"></a><span class='hs-comment'>-- type,) then the term is /polymorphic/ in the answer type.</span>
-<a name="line-45"></a><a name="Delim"></a><span class='hs-comment'>--</span>
-<a name="line-46"></a><a name="Delim"></a><span class='hs-comment'>-- &gt;&gt;&gt; :t runDelim $ reset $ shift2 (\k -&gt; ret k) !&gt;&gt;= \r -&gt; ret (r + (1::Int))</span>
-<a name="line-47"></a><a name="Delim"></a><span class='hs-comment'>-- runDelim $ reset $ shift2 (\k -&gt; ret k) !&gt;&gt;= \r -&gt; ret (r + (1::Int))</span>
-<a name="line-48"></a><a name="Delim"></a><span class='hs-comment'>--   :: Int -&gt; Delim a' a' Int</span>
-<a name="line-49"></a><a name="Delim"></a><span class='hs-comment'>--</span>
-<a name="line-50"></a><a name="Delim"></a><span class='hs-comment'>-- Note how the quantified variable @a'@ is both the input and output</span>
-<a name="line-51"></a><a name="Delim"></a><span class='hs-comment'>-- answer type: thus, @k@ will work with any answer type and is</span>
-<a name="line-52"></a><a name="Delim"></a><span class='hs-comment'>-- polymorphic (in this case, the answer type of the enclosing 'reset'</span>
-<a name="line-53"></a><a name="Delim"></a><span class='hs-comment'>-- is 'Int'.)</span>
-<a name="line-54"></a><a name="Delim"></a><span class='hs-keyword'>newtype</span> <span class='hs-conid'>Delim</span> <span class='hs-varid'>s</span> <span class='hs-varid'>t</span> <span class='hs-varid'>b</span>
-<a name="line-55"></a>  <span class='hs-keyglyph'>=</span> <span class='hs-conid'>Delim</span> <span class='hs-layout'>{</span> <span class='hs-varid'>unDelim</span> <span class='hs-keyglyph'>::</span> <span class='hs-layout'>(</span><span class='hs-varid'>b</span> <span class='hs-keyglyph'>-&gt;</span> <span class='hs-varid'>s</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>-&gt;</span> <span class='hs-varid'>t</span> <span class='hs-layout'>}</span>
-<a name="line-56"></a>
-<a name="line-57"></a><a name="instance%20Monad'%20Delim"></a><span class='hs-comment'>-- | Delimited continuations form a parameterized 'Monad''.</span>
-<a name="line-58"></a><a name="instance%20Monad'%20Delim"></a><span class='hs-keyword'>instance</span> <span class='hs-conid'>Monad'</span> <span class='hs-conid'>Delim</span> <span class='hs-keyword'>where</span>
-<a name="line-59"></a>  <span class='hs-varid'>ret</span> <span class='hs-varid'>x</span>            <span class='hs-keyglyph'>=</span> <span class='hs-conid'>Delim</span> <span class='hs-layout'>(</span><span class='hs-keyglyph'>\</span><span class='hs-varid'>k</span> <span class='hs-keyglyph'>-&gt;</span> <span class='hs-varid'>k</span> <span class='hs-varid'>x</span><span class='hs-layout'>)</span>
-<a name="line-60"></a>  <span class='hs-varid'>bind</span> <span class='hs-layout'>(</span><span class='hs-conid'>Delim</span> <span class='hs-varid'>f</span><span class='hs-layout'>)</span> <span class='hs-varid'>h</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>Delim</span> <span class='hs-layout'>(</span><span class='hs-keyglyph'>\</span><span class='hs-varid'>k</span> <span class='hs-keyglyph'>-&gt;</span> <span class='hs-varid'>f</span> <span class='hs-layout'>(</span><span class='hs-keyglyph'>\</span><span class='hs-varid'>s</span> <span class='hs-keyglyph'>-&gt;</span> <span class='hs-varid'>unDelim</span> <span class='hs-layout'>(</span><span class='hs-varid'>h</span> <span class='hs-varid'>s</span><span class='hs-layout'>)</span> <span class='hs-varid'>k</span><span class='hs-layout'>)</span><span class='hs-layout'>)</span>
-<a name="line-61"></a>
-<a name="line-62"></a><a name="reset"></a><span class='hs-comment'>-- | Delimit a computation.</span>
-<a name="line-63"></a><span class='hs-definition'>reset</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>Delim</span> <span class='hs-varid'>s</span> <span class='hs-varid'>t</span> <span class='hs-varid'>s</span> <span class='hs-keyglyph'>-&gt;</span> <span class='hs-conid'>Delim</span> <span class='hs-varid'>s'</span> <span class='hs-varid'>s'</span> <span class='hs-varid'>t</span>
-<a name="line-64"></a><span class='hs-definition'>reset</span> <span class='hs-layout'>(</span><span class='hs-conid'>Delim</span> <span class='hs-varid'>f</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>Delim</span> <span class='hs-layout'>(</span><span class='hs-keyglyph'>\</span><span class='hs-varid'>k</span> <span class='hs-keyglyph'>-&gt;</span> <span class='hs-varid'>k</span> <span class='hs-layout'>(</span><span class='hs-varid'>f</span> <span class='hs-varid'>id</span><span class='hs-layout'>)</span><span class='hs-layout'>)</span>
-<a name="line-65"></a>
-<a name="line-66"></a><a name="shift0"></a><span class='hs-comment'>-- | Clear the current continuation and invoke our handler with it</span>
-<a name="line-67"></a><span class='hs-comment'>-- bound as a parameter.</span>
-<a name="line-68"></a><span class='hs-comment'>--</span>
-<a name="line-69"></a><span class='hs-comment'>-- This is the most pure definition of @shift@.</span>
-<a name="line-70"></a><span class='hs-definition'>shift0</span> <span class='hs-keyglyph'>::</span> <span class='hs-layout'>(</span><span class='hs-layout'>(</span><span class='hs-varid'>b</span> <span class='hs-keyglyph'>-&gt;</span> <span class='hs-varid'>s</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>-&gt;</span> <span class='hs-varid'>t</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>-&gt;</span> <span class='hs-conid'>Delim</span> <span class='hs-varid'>s</span> <span class='hs-varid'>t</span> <span class='hs-varid'>b</span>
-<a name="line-71"></a><span class='hs-definition'>shift0</span> <span class='hs-varid'>f</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>Delim</span> <span class='hs-varid'>f</span>
-<a name="line-72"></a>
-<a name="line-73"></a><a name="shift1"></a><span class='hs-comment'>-- | Clear the current continuation and invoke our handler with it</span>
-<a name="line-74"></a><span class='hs-comment'>-- bound as a parameter.</span>
-<a name="line-75"></a><span class='hs-comment'>--</span>
-<a name="line-76"></a><span class='hs-comment'>-- This is a simple Haskell98 definition of @shift@ that does not enforce</span>
-<a name="line-77"></a><span class='hs-comment'>-- true answer type polymorphism by abstracting over the internal 's' and</span>
-<a name="line-78"></a><span class='hs-comment'>-- 't' type variables.</span>
-<a name="line-79"></a><span class='hs-definition'>shift1</span> <span class='hs-keyglyph'>::</span> <span class='hs-layout'>(</span><span class='hs-layout'>(</span><span class='hs-varid'>b</span> <span class='hs-keyglyph'>-&gt;</span> <span class='hs-varid'>s</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>-&gt;</span> <span class='hs-conid'>Delim</span> <span class='hs-varid'>a</span> <span class='hs-varid'>t</span> <span class='hs-varid'>a</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>-&gt;</span> <span class='hs-conid'>Delim</span> <span class='hs-varid'>s</span> <span class='hs-varid'>t</span> <span class='hs-varid'>b</span>
-<a name="line-80"></a><span class='hs-definition'>shift1</span> <span class='hs-varid'>f</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>Delim</span> <span class='hs-layout'>(</span><span class='hs-keyglyph'>\</span><span class='hs-varid'>k</span> <span class='hs-keyglyph'>-&gt;</span> <span class='hs-varid'>unDelim</span> <span class='hs-layout'>(</span><span class='hs-varid'>f</span> <span class='hs-varid'>k</span><span class='hs-layout'>)</span> <span class='hs-varid'>id</span><span class='hs-layout'>)</span>
-<a name="line-81"></a>
-<a name="line-82"></a><a name="shift2"></a><span class='hs-comment'>-- | Clear the current continuation and invoke our handler with it</span>
-<a name="line-83"></a><span class='hs-comment'>-- bound as a paramter.</span>
-<a name="line-84"></a><span class='hs-comment'>--</span>
-<a name="line-85"></a><span class='hs-comment'>-- This definition of @shift@ uses Rank-2 types to ensure the answer</span>
-<a name="line-86"></a><span class='hs-comment'>-- type is in fact polymorphic: note the type of the captured continuation</span>
-<a name="line-87"></a><span class='hs-comment'>-- is @Delim t' t' s@.</span>
-<a name="line-88"></a><span class='hs-definition'>shift2</span> <span class='hs-keyglyph'>::</span> <span class='hs-layout'>(</span><span class='hs-layout'>(</span><span class='hs-varid'>b</span> <span class='hs-keyglyph'>-&gt;</span> <span class='hs-keyword'>forall</span> <span class='hs-varid'>a'</span><span class='hs-varop'>.</span>  <span class='hs-conid'>Delim</span> <span class='hs-varid'>a'</span> <span class='hs-varid'>a'</span> <span class='hs-varid'>s</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>-&gt;</span> <span class='hs-conid'>Delim</span> <span class='hs-varid'>a</span> <span class='hs-varid'>t</span> <span class='hs-varid'>a</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>-&gt;</span> <span class='hs-conid'>Delim</span> <span class='hs-varid'>s</span> <span class='hs-varid'>t</span> <span class='hs-varid'>b</span>
-<a name="line-89"></a><span class='hs-definition'>shift2</span> <span class='hs-varid'>f</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>Delim</span> <span class='hs-layout'>(</span><span class='hs-keyglyph'>\</span><span class='hs-varid'>k</span> <span class='hs-keyglyph'>-&gt;</span> <span class='hs-varid'>unDelim</span> <span class='hs-layout'>(</span><span class='hs-varid'>f</span> <span class='hs-varop'>$</span> <span class='hs-keyglyph'>\</span><span class='hs-varid'>t</span> <span class='hs-keyglyph'>-&gt;</span> <span class='hs-varid'>ret</span> <span class='hs-layout'>(</span><span class='hs-varid'>k</span> <span class='hs-varid'>t</span><span class='hs-layout'>)</span><span class='hs-layout'>)</span> <span class='hs-varid'>id</span><span class='hs-layout'>)</span>
-<a name="line-90"></a>
-<a name="line-91"></a><a name="runDelim"></a><span class='hs-comment'>-- | Run a delimited computation.</span>
-<a name="line-92"></a><span class='hs-definition'>runDelim</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>Delim</span> <span class='hs-varid'>t</span> <span class='hs-varid'>t</span> <span class='hs-varid'>t</span> <span class='hs-keyglyph'>-&gt;</span> <span class='hs-varid'>t</span>
-<a name="line-93"></a><span class='hs-definition'>runDelim</span> <span class='hs-layout'>(</span><span class='hs-conid'>Delim</span> <span class='hs-varid'>f</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>f</span> <span class='hs-varid'>id</span>
+<a name="line-40"></a><a name="Delim"></a><span class='hs-comment'>-- @s@ to @t@. The take away from this is that the @s@ and @t@</span>
+<a name="line-41"></a><a name="Delim"></a><span class='hs-comment'>-- variables representing the input and output answer type,</span>
+<a name="line-42"></a><a name="Delim"></a><span class='hs-comment'>-- respectively.</span>
+<a name="line-43"></a><a name="Delim"></a><span class='hs-comment'>--</span>
+<a name="line-44"></a><a name="Delim"></a><span class='hs-comment'>-- If a 'Delim' does not capture the computation using one of the</span>
+<a name="line-45"></a><a name="Delim"></a><span class='hs-comment'>-- various @shift@ operators (or @shift@ does not change the answer</span>
+<a name="line-46"></a><a name="Delim"></a><span class='hs-comment'>-- type,) then the term is /polymorphic/ in the answer type.</span>
+<a name="line-47"></a><a name="Delim"></a><span class='hs-comment'>--</span>
+<a name="line-48"></a><a name="Delim"></a><span class='hs-comment'>-- &gt;&gt;&gt; :t runDelim $ reset $ shift2 (\k -&gt; ret k) !&gt;&gt;= \r -&gt; ret (r + (1::Int))</span>
+<a name="line-49"></a><a name="Delim"></a><span class='hs-comment'>-- runDelim $ reset $ shift2 (\k -&gt; ret k) !&gt;&gt;= \r -&gt; ret (r + (1::Int))</span>
+<a name="line-50"></a><a name="Delim"></a><span class='hs-comment'>--   :: Int -&gt; Delim a' a' Int</span>
+<a name="line-51"></a><a name="Delim"></a><span class='hs-comment'>--</span>
+<a name="line-52"></a><a name="Delim"></a><span class='hs-comment'>-- Note how the quantified variable @a'@ is both the input and output</span>
+<a name="line-53"></a><a name="Delim"></a><span class='hs-comment'>-- answer type: thus, @k@ will work with any answer type and is</span>
+<a name="line-54"></a><a name="Delim"></a><span class='hs-comment'>-- polymorphic (in this case, the answer type of the enclosing 'reset'</span>
+<a name="line-55"></a><a name="Delim"></a><span class='hs-comment'>-- is 'Int'.)</span>
+<a name="line-56"></a><a name="Delim"></a><span class='hs-keyword'>newtype</span> <span class='hs-conid'>Delim</span> <span class='hs-varid'>s</span> <span class='hs-varid'>t</span> <span class='hs-varid'>b</span>
+<a name="line-57"></a>  <span class='hs-keyglyph'>=</span> <span class='hs-conid'>Delim</span> <span class='hs-layout'>{</span> <span class='hs-varid'>unDelim</span> <span class='hs-keyglyph'>::</span> <span class='hs-layout'>(</span><span class='hs-varid'>b</span> <span class='hs-keyglyph'>-&gt;</span> <span class='hs-varid'>s</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>-&gt;</span> <span class='hs-varid'>t</span> <span class='hs-layout'>}</span>
+<a name="line-58"></a>
+<a name="line-59"></a><a name="instance%20Monad'%20Delim"></a><span class='hs-comment'>-- | Delimited continuations form a parameterized 'Monad''.</span>
+<a name="line-60"></a><a name="instance%20Monad'%20Delim"></a><span class='hs-keyword'>instance</span> <span class='hs-conid'>Monad'</span> <span class='hs-conid'>Delim</span> <span class='hs-keyword'>where</span>
+<a name="line-61"></a>  <span class='hs-varid'>ret</span> <span class='hs-varid'>x</span>            <span class='hs-keyglyph'>=</span> <span class='hs-conid'>Delim</span> <span class='hs-layout'>(</span><span class='hs-keyglyph'>\</span><span class='hs-varid'>k</span> <span class='hs-keyglyph'>-&gt;</span> <span class='hs-varid'>k</span> <span class='hs-varid'>x</span><span class='hs-layout'>)</span>
+<a name="line-62"></a>  <span class='hs-varid'>bind</span> <span class='hs-layout'>(</span><span class='hs-conid'>Delim</span> <span class='hs-varid'>f</span><span class='hs-layout'>)</span> <span class='hs-varid'>h</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>Delim</span> <span class='hs-layout'>(</span><span class='hs-keyglyph'>\</span><span class='hs-varid'>k</span> <span class='hs-keyglyph'>-&gt;</span> <span class='hs-varid'>f</span> <span class='hs-layout'>(</span><span class='hs-keyglyph'>\</span><span class='hs-varid'>s</span> <span class='hs-keyglyph'>-&gt;</span> <span class='hs-varid'>unDelim</span> <span class='hs-layout'>(</span><span class='hs-varid'>h</span> <span class='hs-varid'>s</span><span class='hs-layout'>)</span> <span class='hs-varid'>k</span><span class='hs-layout'>)</span><span class='hs-layout'>)</span>
+<a name="line-63"></a>
+<a name="line-64"></a><a name="reset"></a><span class='hs-comment'>-- | Delimit a computation. The type variable @s'@ indicates that</span>
+<a name="line-65"></a><span class='hs-comment'>-- 'reset' is polymorphic in its answer type.</span>
+<a name="line-66"></a><span class='hs-definition'>reset</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>Delim</span> <span class='hs-varid'>s</span> <span class='hs-varid'>t</span> <span class='hs-varid'>s</span> <span class='hs-keyglyph'>-&gt;</span> <span class='hs-conid'>Delim</span> <span class='hs-varid'>s'</span> <span class='hs-varid'>s'</span> <span class='hs-varid'>t</span>
+<a name="line-67"></a><span class='hs-definition'>reset</span> <span class='hs-layout'>(</span><span class='hs-conid'>Delim</span> <span class='hs-varid'>f</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>Delim</span> <span class='hs-layout'>(</span><span class='hs-keyglyph'>\</span><span class='hs-varid'>k</span> <span class='hs-keyglyph'>-&gt;</span> <span class='hs-varid'>k</span> <span class='hs-layout'>(</span><span class='hs-varid'>f</span> <span class='hs-varid'>id</span><span class='hs-layout'>)</span><span class='hs-layout'>)</span>
+<a name="line-68"></a>
+<a name="line-69"></a><a name="shift0"></a><span class='hs-comment'>-- | Clear the current continuation and invoke our handler with it</span>
+<a name="line-70"></a><span class='hs-comment'>-- bound as a parameter.</span>
+<a name="line-71"></a><span class='hs-comment'>--</span>
+<a name="line-72"></a><span class='hs-comment'>-- This is the most pure definition of @shift@.</span>
+<a name="line-73"></a><span class='hs-definition'>shift0</span> <span class='hs-keyglyph'>::</span> <span class='hs-layout'>(</span><span class='hs-layout'>(</span><span class='hs-varid'>b</span> <span class='hs-keyglyph'>-&gt;</span> <span class='hs-varid'>s</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>-&gt;</span> <span class='hs-varid'>t</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>-&gt;</span> <span class='hs-conid'>Delim</span> <span class='hs-varid'>s</span> <span class='hs-varid'>t</span> <span class='hs-varid'>b</span>
+<a name="line-74"></a><span class='hs-definition'>shift0</span> <span class='hs-varid'>f</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>Delim</span> <span class='hs-varid'>f</span>
+<a name="line-75"></a>
+<a name="line-76"></a><a name="shift1"></a><span class='hs-comment'>-- | Clear the current continuation and invoke our handler with it</span>
+<a name="line-77"></a><span class='hs-comment'>-- bound as a parameter.</span>
+<a name="line-78"></a><span class='hs-comment'>--</span>
+<a name="line-79"></a><span class='hs-comment'>-- This is a simple Haskell98 definition of @shift@ that does not enforce</span>
+<a name="line-80"></a><span class='hs-comment'>-- true answer type polymorphism by abstracting over the internal 's' and</span>
+<a name="line-81"></a><span class='hs-comment'>-- 't' type variables.</span>
+<a name="line-82"></a><span class='hs-definition'>shift1</span> <span class='hs-keyglyph'>::</span> <span class='hs-layout'>(</span><span class='hs-layout'>(</span><span class='hs-varid'>b</span> <span class='hs-keyglyph'>-&gt;</span> <span class='hs-varid'>s</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>-&gt;</span> <span class='hs-conid'>Delim</span> <span class='hs-varid'>a</span> <span class='hs-varid'>t</span> <span class='hs-varid'>a</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>-&gt;</span> <span class='hs-conid'>Delim</span> <span class='hs-varid'>s</span> <span class='hs-varid'>t</span> <span class='hs-varid'>b</span>
+<a name="line-83"></a><span class='hs-definition'>shift1</span> <span class='hs-varid'>f</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>Delim</span> <span class='hs-layout'>(</span><span class='hs-keyglyph'>\</span><span class='hs-varid'>k</span> <span class='hs-keyglyph'>-&gt;</span> <span class='hs-varid'>unDelim</span> <span class='hs-layout'>(</span><span class='hs-varid'>f</span> <span class='hs-varid'>k</span><span class='hs-layout'>)</span> <span class='hs-varid'>id</span><span class='hs-layout'>)</span>
+<a name="line-84"></a>
+<a name="line-85"></a><a name="shift2"></a><span class='hs-comment'>-- | Clear the current continuation and invoke our handler with it</span>
+<a name="line-86"></a><span class='hs-comment'>-- bound as a paramter.</span>
+<a name="line-87"></a><span class='hs-comment'>--</span>
+<a name="line-88"></a><span class='hs-comment'>-- This definition of @shift@ uses Rank-2 types to ensure the answer</span>
+<a name="line-89"></a><span class='hs-comment'>-- type is in fact polymorphic: note the type of the captured continuation</span>
+<a name="line-90"></a><span class='hs-comment'>-- is @Delim t' t' s@.</span>
+<a name="line-91"></a><span class='hs-definition'>shift2</span> <span class='hs-keyglyph'>::</span> <span class='hs-layout'>(</span><span class='hs-layout'>(</span><span class='hs-varid'>b</span> <span class='hs-keyglyph'>-&gt;</span> <span class='hs-keyword'>forall</span> <span class='hs-varid'>a'</span><span class='hs-varop'>.</span>  <span class='hs-conid'>Delim</span> <span class='hs-varid'>a'</span> <span class='hs-varid'>a'</span> <span class='hs-varid'>s</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>-&gt;</span> <span class='hs-conid'>Delim</span> <span class='hs-varid'>a</span> <span class='hs-varid'>t</span> <span class='hs-varid'>a</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>-&gt;</span> <span class='hs-conid'>Delim</span> <span class='hs-varid'>s</span> <span class='hs-varid'>t</span> <span class='hs-varid'>b</span>
+<a name="line-92"></a><span class='hs-definition'>shift2</span> <span class='hs-varid'>f</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>Delim</span> <span class='hs-layout'>(</span><span class='hs-keyglyph'>\</span><span class='hs-varid'>k</span> <span class='hs-keyglyph'>-&gt;</span> <span class='hs-varid'>unDelim</span> <span class='hs-layout'>(</span><span class='hs-varid'>f</span> <span class='hs-varop'>$</span> <span class='hs-keyglyph'>\</span><span class='hs-varid'>t</span> <span class='hs-keyglyph'>-&gt;</span> <span class='hs-varid'>ret</span> <span class='hs-layout'>(</span><span class='hs-varid'>k</span> <span class='hs-varid'>t</span><span class='hs-layout'>)</span><span class='hs-layout'>)</span> <span class='hs-varid'>id</span><span class='hs-layout'>)</span>
+<a name="line-93"></a>
+<a name="line-94"></a><a name="runDelim"></a><span class='hs-comment'>-- | Run a delimited computation.</span>
+<a name="line-95"></a><span class='hs-definition'>runDelim</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>Delim</span> <span class='hs-varid'>t</span> <span class='hs-varid'>t</span> <span class='hs-varid'>t</span> <span class='hs-keyglyph'>-&gt;</span> <span class='hs-varid'>t</span>
+<a name="line-96"></a><span class='hs-definition'>runDelim</span> <span class='hs-layout'>(</span><span class='hs-conid'>Delim</span> <span class='hs-varid'>f</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>f</span> <span class='hs-varid'>id</span>
 </pre></body>
 </html>