On Fri, Mar 26, 2010 at 6:01 PM, Jeremy Shaw <span dir="ltr">&lt;<a href="mailto:jeremy@n-heptane.com">jeremy@n-heptane.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;">
A variation which is more obviously hierarchical in nature:<div><br></div><div>data User = User LastName FirstName</div><div>data Section = Recent | TopRated</div><div>data UserHomeURL = Wall Section | Profile</div><div>data UserURL = ViewHome User UserHome</div>

<div><br></div><div>Which would be used to construct urls like:</div><div><br></div><div>/shaw/jeremy/wall/recent</div><div>/snoyman/michael/profile</div></blockquote><div><br></div><div>To expand on this slightly let&#39;s pretend you first implemented a module that supported a single user:</div>
<div><br></div><div><div>data Section = Recent | TopRated</div><div><div>data UserHomeURL = Wall Section | Profile</div><div><br></div><div>And you release that as a library.</div><div><br></div><div>Then in another app, which supports multiple users, you want to use it. So you create:</div>
</div></div><div> </div><div><div>data User = User LastName FirstName</div><div><div>data UserURL = ViewHome User UserHome</div><div><br></div><div>That seems pretty sensible. After all the half the point of this library is to be able to build reusable components. Because we are reusing a component, we can not modify the UserHome portion of the URL. But we still need some way to specify which user&#39;s home we are looking at. The above types seem sensible for that.</div>
<div><br></div><div>You have similar structures in your photo blog app:</div><div><br></div><div>--------</div><div><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>...</div><div>------</div><div><br></div><div>
A reasonable URL type for that might be:</div><div><br></div><div>data EntryId = ...</div><div>data PhotoBlogURL = BlogHome | Entry EntryId | Media EntryId FileName | Feed</div><div><br></div><div>Where Media has two arguments to it&#39;s constructor. You can&#39;t really factor that out, can you? You could fake it like:</div>
<div><br></div><div><div>data PhotoBlogURL = BlogHome | Entry EntryId | Media (EntryId, FileName) | Feed</div><div><br></div><div>But that does not really buy you anything, because when you write the Media parser, you still have to know how many segments EntryId consumes, and how many FileName consumes. </div>
<div><br></div><div>perhaps entryid is:</div><div><br></div><div>data EntryId = EntryId { year :: Int</div><div>                                     , month :: Int</div><div>                                     ,</div><div>
<br></div><div><br></div></div></div></div></div></div>