<br><br><div class="gmail_quote">On Mon, Mar 29, 2010 at 9:18 AM, Jeremy Shaw <span dir="ltr">&lt;<a href="mailto:jeremy@n-heptane.com">jeremy@n-heptane.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
On Mon, Mar 29, 2010 at 8:47 AM, Michael Snoyman <span dir="ltr">&lt;<a href="mailto:michael@snoyman.com" target="_blank">michael@snoyman.com</a>&gt;</span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

Jeremy,<div></div></blockquote><div class="im"><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div>We&#39;d been discussing the PathInfo class previously; I understand now what you&#39;re trying to achieve with it, but I think for a lot of use cases using a parser like that will be unnecesary. For those cases, I&#39;d hate to introduce a parsec dependency, especially given the 2/3 split we&#39;re dealing with right now.</div>

</blockquote><div><br></div></div><div>Well, parsec is in the haskell platform, so it&#39;s really a question of can be it implemented so that it works with both 2 and 3. </div><div class="im"><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

<div></div><div>I know it&#39;s painful to split this up into even more packages, but we do you think of adding web-routes-parser?</div></blockquote><div><br></div></div><div>I would consider it, but I don&#39;t understand how that would work...</div>

<div><br></div><div>So far you have been pretty unexcited about the parsing having a type similar to:</div><div><br></div><div> [String] -&gt; (Either String a, [String])</div><div><br></div><div>because it is often &#39;unnecessary&#39;. But the problem with, [String] -&gt; (Either String a), is that, as far as I can tell, it won&#39;t work in the cases where it *is* necessary. And you can&#39;t simply switch to, [String] -&gt; (Either String a, [String]), when that happens.. But perhaps I am missing something here..</div>
<div class="im">
<div> </div></div></div></blockquote><div>The reason I&#39;m unexcited is that I never would have dreamed of defining my routes that way. I don&#39;t feel like drawing out this point too much, because you clearly *would* define your routes that way. However, just to draw the distinction in how I would do things differently, I&#39;ll use an example of mine that you quoted earlier:</div>
<div><br></div><div><span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; border-collapse: collapse; "><div>instance Yesod PB where</div><div>    resources = [$mkResources|</div><div>/:</div>
<div>    GET: indexHandler</div><div>/entries/$entryId:</div><div>    GET: entry</div><div>/entries/$entryId/$filename:</div><div>    GET: media</div><div>/feed:</div><div>    GET: feed</div><div><br></div><div>If I were to convert this to a datatype, it would be:</div>
<div><br></div><div>data PBRoutes = Home | Entry String | File String String | Feed</div><div><br></div><div>I simply wouldn&#39;t nest a datatype inside any of the constructors. I understand that you want to do this in some circumstances, but I would simply &quot;duplicate&quot; the parsing code for the Entry and File constructors, since I find that parsing code trivial. In particular:</div>
<div><br></div><div>parsePB [&quot;entries&quot;, eid] = Entry eid</div><div>parsePB [&quot;entries&quot;, eid, filename] = File eid filename</div><div><br></div><div>I don&#39;t see a need for providing a sophisticated parser.</div>
<div><br></div></span></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div class="gmail_quote"><div class="im"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div>Also, question about the Site datatype: Did we want the formatLink and parseLink functions to work on [String] instead of String? I think I see advantages either way. Also, I&#39;m not sure if I sent this previously, but I think the defaultPage function is redundant; that should probably be specified by &#39;parseLink &quot;&quot;&#39;.</div>

</blockquote><div><br></div></div><div>I will have to think about [String] vs String more. I don&#39;t want using Site to mean you have to use PathInfo, but switching to [String] wouldn&#39;t have that effect, and would mean that people would not have to worry about those pesky encoding issues. The only real use case I have for not using PathInfo is if you wanted to create a function like: gfromPathSegments :: (Data url) =&gt; PathInfo -&gt; Either String url. And that can be done most easily if PathInfo = [String]. So I think I&#39;ll make that change. In the old code base, where there was no url encoding done by the library, it did not really make a difference. </div>

<div><br></div><div>Regarding defaultPage, not all methods of generating formatLink / parseLink lend themselves to handling &quot;&quot; very easily, so it seemed nice to have a single place that can add that case in, rather than add similar code to all the parsers.. Also, I think that I sometimes changes the landing page of my site. But I think I will make &#39;defaultPage&#39; a Maybe value, and bill it as a way to &#39;override&#39; where &quot;&quot; resolves to.</div>
<div class="im">
<div> </div></div></div></blockquote><div>That sounds good.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div class="gmail_quote"><div class="im">
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div>I&#39;ll try to get started on porting the Yesod mkResources code over to web-routes now.</div></blockquote>
<div><br></div></div><div>awesome!</div><div><br></div><div>- jeremy</div><div> </div></div>
</blockquote></div><br><div>So, I&#39;ve thought about the syntax for this, and I have this idea in mind.</div><div><br></div><div><span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; border-collapse: collapse; "><div>
$(createRoutes MyRoutes [$parseRoutes|</div><div>/:</div><div>  name: Home</div><div>  methods: [GET]</div><div>/user/#userid:</div><div>  name: User</div><div>  methods: [GET, PUT, DELETE]</div><div>/static:</div><div>  name: Static</div>
<div>  subsite: StaticRoutes</div><div>  dispatch: staticRoutes</div><div>|])</div><div><br></div><div>This would generate a datatype:</div><div><br></div><div>data MyRoutes = Home | User Integer | Static StaticRoutes</div>
<div><br></div><div>Handler functions would be getHome, getUser, putUser, deleteUser. Static would be a pluggable subsite; I&#39;d have to play around with the syntax of that a bit. Also, this will allow *any* type of application, not just wai (I want this to be as general as possible).</div>
<div><br></div><div>Michael</div></span></div>