Hsthrift: Open-sourcing Thrift for Haskell

What is it:

thrift is a serialization and remote procedure call (RPC) framework used for cross-service communication. Most services on Facebook communicate via Thrift, as it offers a simple, language-independent protocol for communicating with structured data. Thrift can already be used in programming languages ​​such as C ++, Python and Java fbthrift. We also offer open sourcing thrift support for Haskell (hsthrift).

The hsthrift package contains the complete collection of tools and libraries for using Thrift in your own Haskell projects. The Haskell Thrift compiler generates the Haskell code required to communicate with other Thrift services. With the included libraries you can create both Thrift clients and servers in Haskell. Haskell Thrift is fully compatible with all other fbthrift languages, so your Haskell project can communicate freely with other services, regardless of 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 advanced functions, including:

  • Required symbols: The Haskell Thrift compiler can clean the generated code before type checking to remove unused symbols. The symbols required can either be specified manually or derived automatically.
  • Exactprint: Inspired by ghc-exact printWe also have an accurate printing library for Thrift that allows you to perform transformations on the Thrift Abstract Syntax Tree (AST) while preserving the original formatting of the code. Due to the correct design of the compiler, it is guaranteed that all transformations of the type-tested AST are well typed.
  • Typechecker plugins: The Haskell Thrift compiler has a mechanism for specifying type checking plug-ins that allow you to adapt the type checking rules to the target language. This makes it easy to create new backends for the compiler.
  • Splice: You can include additional type class instances in the generated code to avoid creating orphaned instances in other files.

Why it matters:

Practically distributed systems require efficient, type-safe and 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 this option to create efficient distributed systems in Haskell or to integrate Haskell clients and servers into an existing Thrift-based system.

The Haskell Thrift Compiler is also the subject of a recent paper on using advanced features of the Haskell type system to eliminate errors in production. Now that the code is open source, other Haskell developers can benefit from real examples of how we’ve used these techniques to great effect on Facebook.

Get it on GitHub:

Hsthrift

Comments are closed.