Hello,<div><br></div><div>It looks nearly identical, but without the URLT monad transformer. </div><div><br></div><div>Instead of ToURL I have the class:</div><div><br></div><div><div>class AsURL a where</div><div>    toURLS :: a -&gt; ShowS</div>
<div>    fromURLC :: Consumer String (Failing a)</div><div><br></div><div>With is basically the same. Except toURLS returns a ShowS instead of [String]. fromURLC consumes a list of [String]. These functions are wrapped up to provide:</div>
<div><br></div><div>toURL :: (AsURL a) =&gt; a -&gt; String</div><div>fromURL :: (AsURL a) =&gt; String -&gt; Failing a</div><div><br></div><div>I do not have generics based url printing/parsing, but there is no reason it could not be added. I do have template haskell based code though. </div>
<div><br></div><div><a href="http://src.seereason.com/urlt/URLT/TH.hs">http://src.seereason.com/urlt/URLT/TH.hs</a></div><div><br></div><div>The thing you don&#39;t have is the URLT monad transformer:</div><div><br></div>
<div><a href="http://src.seereason.com/urlt/URLT/Base.hs">http://src.seereason.com/urlt/URLT/Base.hs</a></div><div><br></div><div>Here is why you want it. Imagine you write an image gallery library:</div><div><br></div><div>
data ImageURL = Upload | ViewImage Int</div><div><br></div><div>when you call toURL, you are going to get urls like, /Upload, /ViewImage/1, etc.</div><div><br></div><div>Now let&#39;s say I try to use your library in my application. So at first I try:</div>
<div><br></div><div>data MyApp = Upload | FooBar</div><div><br></div><div>But when a URL comes in, how do I know if I should decode it as MyApp or ImageURL? Do I try both and see which one succeeds? Except we both have a constructor Upload, so both will succeed. There is no way to tell with Upload the path &quot;/Upload&quot; is referring to.</div>
<div><br></div><div>So now I try:</div><div><br></div><div>data MyApp = Upload | FooBar | Images ImageURL</div><div><br></div><div>now I know that all incoming urls are decoded as MyApp. But there is still a problem. In my code I could write:</div>
<div><br></div><div> toUrl (Images (ViewImage 1))</div><div><br></div><div>but in your library code, you don&#39;t know anything about the Images constructor. So you just call,</div><div><br></div><div>toURL (ViewImage 1)</div>
<div><br></div><div>which generates /ViewImage/1 instead of the required /Images/ViewImage/1.</div><div><br></div><div>What I need is someway to tell your library code what prefix to add at the beginning. That is exactly what the URLT monad does. It just holds a function that adds a prefix to the URL.</div>
<div><br></div><div>so in your library you have:</div><div><br></div><div>image :: ImageURL -&gt; URLT ImageURL m ()</div><div>image Upload = </div><div>     do ...</div><div>          u &lt;- showURL (ViewImage n)</div><div>
          ...</div><div>image (ViewImage num) = ...</div><div><br></div><div>Instead of calling toURL, it calls showURL, which adds the context to the URL and then calls toURL on it.</div><div><br></div><div>And in my code I have:</div>
<div><br></div><div>myApp :: MyAPP -&gt; URLT MyApp m ()</div><div>mpApp Upload = ...</div><div>myApp FooBar = ...</div><div>myApp (Images subURL) = nestURL Images $ images subURL </div><div><br></div><div>the &#39;nextURL Images&#39; adds the Images context to the URLT environment. It can be used to nest multiple levels if needed:</div>
<div><br></div><div> nestURL A $ nestURL B $ nestURL Images $ showURL (ViewImage 1) </div><div><br></div><div>would get turned into something like:</div><div><br></div><div> &quot;/A/B/Images/ViewImage/1&quot;</div><div><br>
</div><div>What do you think?</div><div><br></div><div>- jeremy</div><div><br></div></div><div><br><div class="gmail_quote">On Tue, Mar 16, 2010 at 3:52 AM, Chris Eidhof <span dir="ltr">&lt;<a href="mailto:chris@eidhof.nl">chris@eidhof.nl</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">Hey everyone,<br>
<br>
I just wrote down some of my ideas about type-safe URL handling on github, it&#39;s at <a href="http://gist.github.com/333769" target="_blank">http://gist.github.com/333769</a><br>
<br>
I think it&#39;s similar to what Jeremy is doing with his urlt package [1].<br>
<br>
-chris<br>
<br>
[1]: <a href="http://src.seereason.com/~jeremy/SimpleSite1.html" target="_blank">http://src.seereason.com/~jeremy/SimpleSite1.html</a><br>
<br>
_______________________________________________<br>
web-devel mailing list<br>
<a href="mailto:web-devel@haskell.org">web-devel@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/web-devel" target="_blank">http://www.haskell.org/mailman/listinfo/web-devel</a><br>
</blockquote></div><br></div>