[web-devel] WAI Routing
Stephen Paul Weber
singpolyma at singpolyma.net
Thu Aug 9 16:10:39 CEST 2012
-----BEGIN PGP SIGNED MESSAGE-----
Somebody claiming to be yi huang wrote:
> Why prefer code generation over template Haskell? Isn't them essentially
> the same thing, and template haskell is performed automatically.
Also, from Reddit (nicolast):
> I never understood why someone would want to avoid using language
> extensions which have been in GHC for at least some time. The only reason
> I can think of is: compatibility with other compilers. But is anyone ever
> going to compile/run a yesod-routes based application using something
> other than GHC?!
First off, yes, Template Haskell is very similar to code generation. There
are a few reasons I would like to avoid it.
It's a language extension. I try to avoid those in general, in every
stanardized language I code in (C89, R5RS, Haskell98) for several reasons.
As nicolast said, compatibility with other compilers is a big one. When
I get a piece of code from someone who assumed that "what MSVC does" or
"what Racket does" is the same as "anyone can run this", it makes it quite
difficult to use my favourite implementations of those languages. I don't
want to make assumptions about other people's environments, or what will be
useful in the future. Maybe someone writes a Haskell interpreter that makes
use in some context I haven't even imagined much nicer. Who knows.
Additionally, any other static analysis/code processing tools (like, say,
hlint) *also* needs to support whatever syntax extensions you're using
(semantics exceptions may or may not apply here, dependings on the nature of
the tool). Requiring that every tool author support all my favourite
extensions limits my tool options, and makes life harder for tool authors
(since they cannot just look in one place for the spec and write to that
anymore if they need to look up compilers' extensions as well).
Will anyone ever compile/run/analyze a yesod-routes based application using
something other than GHC/hlint? (Actually, does hlint support TH. It
might.) What specifically about yesod-routes makes this less likely? What
drew me to Yesod.Routes.Dispatch was its relative purity in terms of
Additionally, I find Template Haskell specifically (and some other language
extensions, like Overlapping Instances) can make code harder to read (for
me) and possibly harder to reason about. A code generator makes a file that
I can read for comprehension, edit if I want to, etc.
Ok, that's a bit of a long answer to a short question, but it sort of sums
up my motivation vis extensions in general and TH in particular.
Stephen Paul Weber, @singpolyma
See <http://singpolyma.net> for how I prefer to be contacted
edition right joseph
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
-----END PGP SIGNATURE-----
More information about the web-devel