<div dir="ltr"><br><br><div class="gmail_quote">On Mon, May 24, 2010 at 8:49 PM, Gregory Collins <span dir="ltr">&lt;<a href="mailto:greg@gregorycollins.net" target="_blank">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>Andrey Popp &lt;<a href="mailto:8mayday@gmail.com" target="_blank">8mayday@gmail.com</a>&gt; writes:<br>
<br>
&gt; Related to URL routing solutions in Yesod and Snap — I&#39;ve found the<br>
&gt; Snap way to be more comfortable, maybe this is because the same syntax<br>
&gt; is used by Python/Ruby web frameworks (I personally have experience<br>
&gt; with many Python web frameworks). Also I don&#39;t think that URL routing<br>
&gt; type safety is also very important here.<br>
<br>
</div>There is actually nothing stopping us from providing a typesafe URL<br>
routing engine; we just haven&#39;t done it yet because like you, it isn&#39;t<br>
very important to us. Some people really like it though, so I can see us<br>
providing something eventually.<br>
<div><br></div></blockquote><div>I&#39;m just curious if anyone&#39;s actually *used* type-safe URLs in production web apps. I&#39;m not really aware of an implementation besides what Jeremy Shaw has done (first urlt and then web-routes). I&#39;m afraid that the technique is not getting the credit it deserves.</div>


<div><br></div><div>When I say type-safe URLs, I&#39;m talking about having a datatype which represents all possible routes in an application, a function to convert from that datatype to a String, and a function to attempt converting a String to that datatype. As a simple example:</div>


<div><br></div><div>data MyBlog = BlogHome | BlogEntry String | AtomFeed</div><div><br></div><div>Then, instead of typing something like &quot;/entries/&quot; ++ entryName ++ &quot;/&quot;, you just type BlogEntry entryName. In this simple case, it doesn&#39;t do much more than ensure you don&#39;t make typos.</div>
<div><br></div><div>I can&#39;t go into details, but I had a project where I needed to change an entity relationship from  many-to-many to many-to-one, and suddenly I had to remove an extraneous parameter from all of my routes. Due to type-safe URLs, I changed the datatype and the compiler caught each and every time I needed to modify the code.</div>
<div><br></div><div>More simply, if I decide suddenly to rename &quot;/entry/1/&quot; to &quot;/post/1/&quot;, I only need to change the URL rendering function and all of my code is updated automatically.</div><div><br></div>
<div>This monologue isn&#39;t meant as a Yesod-is-better-than-Snap, it&#39;s meant to point out that type-safe URLs are a very powerful feature, and I think it fits very nicely with the Haskell nature. I&#39;d really urge people to look hard at them and consider using them.</div>
<div><br></div><div>Michael</div>

</div></div>