Haskell and Lua share some similarities, like
support for functional programming, but are otherwise very
different. Nonetheless, the two complement each other in
interesting ways. This is demonstrated by pandoc, the
universal document converter, which is written in Haskell and
uses Lua as extension language. Pandoc’s behavior can be
modified through Lua filters, custom readers, and custom
writers, leveraging the power of Haskell and flexibility of
Lua.
While combining the two languages is made easy by the hslua
package, the internals of that package are not always
straight-forward and a testament to the powers of Haskell’s
Foreign Function Interface. We will take a look at the
encountered impedance mismatch and how it was overcome,
compare it to efforts in adjacent languages like OCaml, and
see how hslua can be used to expose application internals to
scripts effectively and conveniently.