<br><br><div class="gmail_quote">On Tue, Mar 16, 2010 at 9:51 AM, Gregory Collins <span dir="ltr"><<a href="mailto:greg@gregorycollins.net">greg@gregorycollins.net</a>></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 <<a href="mailto:michael@snoyman.com">michael@snoyman.com</a>> writes:<br>
<br>
> I think the only piece of the puzzle missing to combine these two<br>
> together is to have mkResources output something along the lines of:<br>
><br>
> data RoutePiece = StaticPiece String | IntPiece | StringPiece<br>
> _validRoutes :: [[RoutePiece]]<br>
> _validRoutes =<br>
> [ [StaticPiece "user"]<br>
> , [StaticPiece "user", StaticPiece "find", IntPiece]<br>
> , [StaticPiece "user", StaticPiece "name", StringPiece]<br>
> ]<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>
-> (WhateverYourWebMonadIsCalled a)<br>
-> (WhateverYourWebMonadIsCalled a)<br>
<br>
And write<br>
<br>
handler = match "/foo/:bar/#int/" $ 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'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 "subtree" to another place in the<br>
routing table in O(1) time.<br>
<br>
This rabbit hole goes pretty deep though; if you're serious about the<br>
bondage and discipline approach you'd want to ensure that you can check<br>
query parameters; i.e. "'/foo' takes a mandatory 'bar' integer parameter<br>
on the queryString and an optional 'sort' parameter which must be either<br>
'asc' or 'desc'", 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'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 "where am I hung on the tree" issue. However, I'll have to think hard to come up with an example which actually makes sense.</div>
<div><br></div><div>Michael</div></div>