<div dir="ltr"><br><br><div class="gmail_quote">On Mon, May 24, 2010 at 8:49 PM, Gregory Collins <span dir="ltr"><<a href="mailto:greg@gregorycollins.net" target="_blank">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>Andrey Popp <<a href="mailto:8mayday@gmail.com" target="_blank">8mayday@gmail.com</a>> writes:<br>
<br>
> Related to URL routing solutions in Yesod and Snap — I've found the<br>
> Snap way to be more comfortable, maybe this is because the same syntax<br>
> is used by Python/Ruby web frameworks (I personally have experience<br>
> with many Python web frameworks). Also I don't think that URL routing<br>
> 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't done it yet because like you, it isn'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'm just curious if anyone's actually *used* type-safe URLs in production web apps. I'm not really aware of an implementation besides what Jeremy Shaw has done (first urlt and then web-routes). I'm afraid that the technique is not getting the credit it deserves.</div>
<div><br></div><div>When I say type-safe URLs, I'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 "/entries/" ++ entryName ++ "/", you just type BlogEntry entryName. In this simple case, it doesn't do much more than ensure you don't make typos.</div>
<div><br></div><div>I can'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 "/entry/1/" to "/post/1/", 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't meant as a Yesod-is-better-than-Snap, it'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'd really urge people to look hard at them and consider using them.</div>
<div><br></div><div>Michael</div>
</div></div>