<br><br><div class="gmail_quote">On Mon, Mar 29, 2010 at 9:18 AM, Jeremy Shaw <span dir="ltr"><<a href="mailto:jeremy@n-heptane.com">jeremy@n-heptane.com</a>></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"><<a href="mailto:michael@snoyman.com" target="_blank">michael@snoyman.com</a>></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'd been discussing the PathInfo class previously; I understand now what you'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'd hate to introduce a parsec dependency, especially given the 2/3 split we're dealing with right now.</div>
</blockquote><div><br></div></div><div>Well, parsec is in the haskell platform, so it'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'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'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] -> (Either String a, [String])</div><div><br></div><div>because it is often 'unnecessary'. But the problem with, [String] -> (Either String a), is that, as far as I can tell, it won't work in the cases where it *is* necessary. And you can't simply switch to, [String] -> (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'm unexcited is that I never would have dreamed of defining my routes that way. I don'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'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't nest a datatype inside any of the constructors. I understand that you want to do this in some circumstances, but I would simply "duplicate" the parsing code for the Entry and File constructors, since I find that parsing code trivial. In particular:</div>
<div><br></div><div>parsePB ["entries", eid] = Entry eid</div><div>parsePB ["entries", eid, filename] = File eid filename</div><div><br></div><div>I don'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'm not sure if I sent this previously, but I think the defaultPage function is redundant; that should probably be specified by 'parseLink ""'.</div>
</blockquote><div><br></div></div><div>I will have to think about [String] vs String more. I don't want using Site to mean you have to use PathInfo, but switching to [String] wouldn'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) => PathInfo -> Either String url. And that can be done most easily if PathInfo = [String]. So I think I'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 "" 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 'defaultPage' a Maybe value, and bill it as a way to 'override' where "" 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'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'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'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>