<br><br><div class="gmail_quote">On Tue, Mar 16, 2010 at 9:51 AM, Gregory Collins <span dir="ltr">&lt;<a href="mailto:greg@gregorycollins.net">greg@gregorycollins.net</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div class="im">Michael Snoyman &lt;<a href="mailto:michael@snoyman.com">michael@snoyman.com</a>&gt; writes:<br>
<br>
&gt; I think the only piece of the puzzle missing to combine these two<br>
&gt; together is to have mkResources output something along the lines of:<br>
&gt;<br>
&gt; data RoutePiece = StaticPiece String | IntPiece | StringPiece<br>
&gt; _validRoutes :: [[RoutePiece]]<br>
&gt; _validRoutes =<br>
&gt;   [ [StaticPiece &quot;user&quot;]<br>
&gt;   , [StaticPiece &quot;user&quot;, StaticPiece &quot;find&quot;, IntPiece]<br>
&gt;   , [StaticPiece &quot;user&quot;, StaticPiece &quot;name&quot;, StringPiece]<br>
&gt;   ]<br>
<br>
</div>Yes, this approach smells a lot better to me: the types are types and<br>
the data are data. Just a brainstorm: if each handler monad were to<br>
carry its routing table around with it, you could define something like:<br>
<br>
    match :: ByteString<br>
          -&gt; (WhateverYourWebMonadIsCalled a)<br>
          -&gt; (WhateverYourWebMonadIsCalled a)<br>
<br>
And write<br>
<br>
    handler = match &quot;/foo/:bar/#int/&quot; $ do ...<br>
<br>
without the template haskell quasiquotation (i.e. do the checking at<br>
runtime.) Is it always true that compile-time link checking is<br>
possible/desirable? All of these solutions also imply that each handler<br>
knows where it&#39;s hung on the routing table so that it can resolve<br>
relative URLs, etc.<br>
<br>
IMO no matter what a link-checker should be lightweight enough that you<br>
can refactor easily without rewriting a bunch of static tables; you<br>
should be able to move an entire &quot;subtree&quot; to another place in the<br>
routing table in O(1) time.<br>
<br>
This rabbit hole goes pretty deep though; if you&#39;re serious about the<br>
bondage and discipline approach you&#39;d want to ensure that you can check<br>
query parameters; i.e. &quot;&#39;/foo&#39; takes a mandatory &#39;bar&#39; integer parameter<br>
on the queryString and an optional &#39;sort&#39; parameter which must be either<br>
&#39;asc&#39; or &#39;desc&#39;&quot;, etc. At some point I have to wonder: is the medicine<br>
worse than the disease?<br>
<br></blockquote><div>I think you have some valid points here. If anyone cares to dig back through the Yesod repo far enough, they&#39;ll find an approach very similar to this, which I replaced with the quasi-quotation approach due to the boilerplate. However, if regular can clean up the boilerplate, maybe this *is* a better approach.</div>
<div><br></div><div>Also, it seems like pairing this up with a dispatch system and a model layer would actually allow fully pluggable components, assuming we can address the &quot;where am I hung on the tree&quot; issue. However, I&#39;ll have to think hard to come up with an example which actually makes sense.</div>
<div><br></div><div>Michael</div></div>