Meeting notes for August 8th: Yesod, QuasiQuote, Parsec and Template Haskell

19 views
Skip to first unread message

Igal Koshevoy

unread,
Aug 15, 2011, 7:19:54 PM8/15/11
to pdxfunc
We had an awesome meeting last week and I'm grateful to all of you there.

We took a deep dive into the implementation of the Yesod web framework
for Haskell. The framework makes it easy for those using it to
configure its behavior, but the underlying implementation that
provides this user-facing simplicity is quite involved. We explored
the code together by throwing out questions about what we didn't
understand and then had others offer explanations or suggestions about
how to dig through the Haskell docs, reference materials, and Yesod
code to figure out how it worked. Between the ~18 of us there, we had
just enough knowledge, ingenuity, and command-line fu needed to
reverse-engineer what Yesod was doing. :)


We learned about:

* Writing embedded domain specific languages using QuasiQuote to
describe complex behavior. Yesod features many such languages,
including one to succinctly describe how to route HTTP requests to
Haskell functions based on their URLs, path parameters, and HTTP
methods.

* Parsing custom languages using the Parsec monadic parser combinator
library. Yesod includes some moderately complex languages that require
defining a grammar and dealing with tricky issues like looking ahead
to parse compound expressions together, e.g., the `$ if` and `$ else`
clauses in an HTML template.

* Performing compile-time meta-programming using Template Haskell.
Yesod's domain specific languages set up complex behavior that
(lesser?) languages would need "eval" to implement. Yesod is able to
avoid "eval" and implement this behavior by using Template Haskell to
build fast, type-safe code. For example, Yesod's HTML templating
language features its own control flow syntax (e.g. `$ if ...`) that
Yesod parses and turns into fast, safe executable Haskell code.


We also found that the "hasktags" tool available through Cabal is very
useful for generating tags that vi and Emacs can use to navigate
through code. For example, after installing the package, you can
generate vi-compatible tags for a directory containing Haskell code by
running:

find -type f -name '*.*hs' -print0 | xargs -0 hasktags -c


Anyway, I had a great time, learned a lot, and would be interested in
future code spelunking exercises. If you find an interesting app,
library or such that would be interesting to explore, please suggest
it.

-igal

Reply all
Reply to author
Forward
0 new messages