Skip to content

Commit ad2b4f0

Browse files
committed
Built from e0097e1
1 parent ccfe1f5 commit ad2b4f0

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

posts/2018-07-12-servant-dsl-typelevel.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ <h1>A first modular attempt</h1>
273273
<a class="sourceLine" id="cb14-19" data-line-number="19"> <span class="co">-- we see that our little `LinkType` trick there allows</span></a>
274274
<a class="sourceLine" id="cb14-20" data-line-number="20"> <span class="co">-- link to receive arguments when appropriate</span></a>
275275
<a class="sourceLine" id="cb14-21" data-line-number="21"> link (<span class="dt">Capture</span> <span class="fu">:&gt;</span> api) captureValue <span class="fu">=</span> captureValue <span class="fu">:</span> link api</a></code></pre></div>
276-
<p>Looks good. Except that this does not typecheck. The problem is with the <code>Capture :&gt; api</code> and <code>Static :&gt; api</code> instances. While we know that the <code>link</code> function will eventually return a <code>Link</code>, once given arguments for all the <code>Capture</code>s, we don’t know whether there is another <code>Capture</code> later in <code>api</code>. If there is, then <code>link api</code> would have type e.g <code>String -&gt; Link</code>, and we cannot cons a <code>String</code> on top of… function.</p>
276+
<p>Looks good. Except that this does not typecheck. The problem is with the <code>Capture :&gt; api</code> and <code>Static :&gt; api</code> instances. While we know that the <code>link</code> function will eventually return a <code>Link</code>, once given arguments for all the <code>Capture</code>s, we don’t know whether there is another <code>Capture</code> later in <code>api</code>. If there is, then <code>link api</code> would have type e.g <code>String -&gt; Link</code>, and we cannot cons a <code>String</code> on top of… a function.</p>
277277
<p>We have to be a little smarter and accumulate the path components as we go without building up the final list directly. We will be accumulating the path components in reverse order, to make the accumulation efficient, and reverse the whole list at the end to give the final <code>Link</code> (<code>= [String]</code>) value.</p>
278278
<div class="sourceCode" id="cb15"><pre class="sourceCode haskell"><code class="sourceCode haskell"><a class="sourceLine" id="cb15-1" data-line-number="1"><span class="ot">link ::</span> <span class="dt">HasLink</span> endpoint <span class="ot">=&gt;</span> endpoint <span class="ot">-&gt;</span> <span class="dt">LinkType</span> endpoint</a>
279279
<a class="sourceLine" id="cb15-2" data-line-number="2">link e <span class="fu">=</span> link' e []</a>

rss.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@
259259
<a class="sourceLine" id="cb14-19" data-line-number="19"> <span class="co">-- we see that our little `LinkType` trick there allows</span></a>
260260
<a class="sourceLine" id="cb14-20" data-line-number="20"> <span class="co">-- link to receive arguments when appropriate</span></a>
261261
<a class="sourceLine" id="cb14-21" data-line-number="21"> link (<span class="dt">Capture</span> <span class="fu">:&gt;</span> api) captureValue <span class="fu">=</span> captureValue <span class="fu">:</span> link api</a></code></pre></div>
262-
<p>Looks good. Except that this does not typecheck. The problem is with the <code>Capture :&gt; api</code> and <code>Static :&gt; api</code> instances. While we know that the <code>link</code> function will eventually return a <code>Link</code>, once given arguments for all the <code>Capture</code>s, we don’t know whether there is another <code>Capture</code> later in <code>api</code>. If there is, then <code>link api</code> would have type e.g <code>String -&gt; Link</code>, and we cannot cons a <code>String</code> on top of… function.</p>
262+
<p>Looks good. Except that this does not typecheck. The problem is with the <code>Capture :&gt; api</code> and <code>Static :&gt; api</code> instances. While we know that the <code>link</code> function will eventually return a <code>Link</code>, once given arguments for all the <code>Capture</code>s, we don’t know whether there is another <code>Capture</code> later in <code>api</code>. If there is, then <code>link api</code> would have type e.g <code>String -&gt; Link</code>, and we cannot cons a <code>String</code> on top of… a function.</p>
263263
<p>We have to be a little smarter and accumulate the path components as we go without building up the final list directly. We will be accumulating the path components in reverse order, to make the accumulation efficient, and reverse the whole list at the end to give the final <code>Link</code> (<code>= [String]</code>) value.</p>
264264
<div class="sourceCode" id="cb15"><pre class="sourceCode haskell"><code class="sourceCode haskell"><a class="sourceLine" id="cb15-1" data-line-number="1"><span class="ot">link ::</span> <span class="dt">HasLink</span> endpoint <span class="ot">=&gt;</span> endpoint <span class="ot">-&gt;</span> <span class="dt">LinkType</span> endpoint</a>
265265
<a class="sourceLine" id="cb15-2" data-line-number="2">link e <span class="fu">=</span> link&#39; e []</a>

0 commit comments

Comments
 (0)