[web-devel] WAI Routing

yi huang yi.codeplayer at gmail.com
Thu Aug 9 07:27:02 CEST 2012

Why prefer code generation over template Haskell? Isn't them essentially
the same thing, and template haskell is performed automatically.

On Thu, Aug 9, 2012 at 11:25 AM, Stephen Paul Weber <
singpolyma at singpolyma.net> wrote:

> I'm back!  I've walked in the desert for a bit longer than last time I was
> on this list, and have a much better handle on Haskell base concepts, which
> is useful.
> So, I re-looked-at yesod-routes as it exists now, and
> Yesod.Routes.Dispatch is very nice for doing the sort of thing I want.
>  Doesn't even use any language extensions itself!  (Oh, almost, it uses
> bang patterns.  Or is that not an extension when used in a datatype?
>  Anyway...)
> Unfortunately, using Yesod.Routes.Dispatch by itself is a bit verbose.  Of
> course, yesod-routes has all kinds of nice utilities to help with that, but
> they are very TH-heavy, so I set out to build a different way: code
> generation!
> The result is: <http://hackage.haskell.org/**package/route-generator<http://hackage.haskell.org/package/route-generator>>
> which takes in a simple text file format (attoparsec FTW!) and outputs a
> module that can be compiled into any application using yesod-routes and
> provide a list of routes based on the text file.  The types of the captured
> URI segments are inferred from the types of the actual Haskell code that
> handles the route.
> The generator assumes a single module that it will import exports names
> for all of the handlers, but I don't think this is too bad since you can
> always have a module that just re-exports all the handlers from wherever
> you define them.
> A simple example is in the git repository.
> I have also pushed up <http://hackage.haskell.org/**package/wai-dispatch<http://hackage.haskell.org/package/wai-dispatch>>,
> which is a simple wrapper around Yesod.Routes.Dispatch for use in WAI apps
> to convert a "default" (likely 404 or static file serving) Application, and
> a list of Route for yesod-route, into an Application that does the routing.
>  It's very little code, but I immidiately identified it as code that would
> end up appearing in every single one of my web apps, so I abstracted it out
> into a tiny library.
> --
> Stephen Paul Weber, @singpolyma
> See <http://singpolyma.net> for how I prefer to be contacted
> edition right joseph
> _______________________________________________
> web-devel mailing list
> web-devel at haskell.org
> http://www.haskell.org/mailman/listinfo/web-devel

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/web-devel/attachments/20120809/08655c10/attachment.htm>

More information about the web-devel mailing list