What it is:
Thrift is a serialization and remote procedure call (RPC) framework used for cross-service communication. Most services at Facebook communicate via Thrift because it provides a simple, language-agnostic protocol for communicating with structured data. Thrift can already be used in programming languages such as C++, Python, and Java using fbthrift. We are also open-sourcing Thrift support for Haskell (hsthrift).
The hsthrift package includes the full collection of tools and libraries for using Thrift in your own Haskell projects. The Haskell Thrift compiler generates the Haskell code needed to communicate with other Thrift services, and the included libraries allow you to build both Thrift clients and servers in Haskell. Haskell Thrift is fully compatible with all other fbthrift languages, so your Haskell project can freely communicate with other services no matter what language they are implemented in!
What it does:
In addition to the standard Thrift tooling suite for cross-service communication, the Haskell Thrift toolchain also supports more advanced functionality, including:
- Required symbols: The Haskell Thrift compiler has the ability to prune the generated code prior to type checking in order to remove unused symbols. The required symbols can be either manually specified or automatically inferred.
- Exactprint: Inspired by ghc-exactprint, we also have an exactprint library for Thrift that allows you to perform transformations on the Thrift abstract syntax tree (AST) while preserving the code’s original formatting. Because of the compiler’s correct-by-construction design, any transformations on the type checked AST are guaranteed to be well typed.
- Typechecker plugins: The Haskell Thrift compiler has a mechanism to specify type checking plugins that allow you to tailor the type checking rules to the target language. This makes it easy to build new back ends for the compiler.
- Splicing: You can splice additional typeclass instances into the generated code to avoid creating orphan instances in other files.
Why it matters:
Practical distributed systems require efficient, type-safe, language-independent RPC support. Thrift is a battle-tested solution to these problems, and hsthrift builds on the efficient foundation of fbthrift to provide Thrift support for Haskell projects. Use it to build efficient distributed systems in Haskell or to incorporate Haskell clients and servers into an existing Thrift-based system.
The Haskell Thrift compiler is also the subject of a recent paper about using advanced features of Haskell’s type system to eliminate bugs in production. Now that the code is open source, other Haskell developers can benefit from real examples of how we have used these techniques to great effect at Facebook.