Facebook releases Retrie for sprucing up complex Haskell projects

Facebook releases Retrie for sprucing up complex Haskell projects

Facebook’s development team has open-sourced code refactoring tool Retrie for large Haskell codebases. 

Retrie is MIT licensed and just one of the openly available tools for Haskell the company has released. In 2015 for example, it introduced the public to remote data access library Haxl, which can be used to automatically batch requests to the same data source, concurrently request data from multiple sources, cache previous requests, and memorize computations.

The new project is meant to improve a codebase’s overall design – especially for complex systems like the ones supposedly operated at Facebook. Compared to other refactoring tools that use either string replacement or parse an abstract syntax tree for manipulation, the dev team claims that Retrie is both fast and allows for an easy way to express more complicated code rewrites. 

To achieve this, it offers developers the option of expressing rewrites as equations in Haskell. Retrie can then apply the equations to all modules in the current directory to modify code. This approach allows the scripting of rewrites and an enforcement of side-conditions, which is useful to automate the process.

It is also claimed that Retrie uses “several techniques to narrow the search space before parsing and efficiently finding matches” making it faster than approaches leveraging syntax trees. Other highlighted features include whitespace preservation, and correctness, since Retrie apparently respects local scoping, forbids to match incomplete expression fragments, and removes/adds parentheses as needed.

Examples for how Retrie can be used are available in the project’s repository and the announcement post.

While Haskell doesn’t seem to be too popular at 30 years of age, Facebook swears by it for fighting spam and malware. Just five years ago, the company replaced its self-made FXL language in rule engine Sigma. Said anti-abuse system is now also the testing playground for Retrie, with Facebook stating that the tool allowed the migration of Sigma rules to new APIs and libraries. 

Other companies that used Haskell for their dealings include financial institutions like Deutsche Bank, Credit Suisse, and ABN AMRO, as well as telecommunications company Ericsson. The former are especially known for having long running software projects, which is why Retrie could very well find some supporters dealing with “historically grown” codebases in those ranks.