TL;DR
Hsrs is a newly announced tool that generates type-safe Haskell bindings for Rust code, automating FFI creation with serialization via Borsh. It aims to streamline cross-language development.
The developer community on Hacker News has introduced Hsrs, a tool that automatically generates type-safe Haskell bindings for Rust code, streamlining cross-language development and reducing boilerplate.
Hsrs allows developers to annotate their Rust code with specific macros, such as #[hsrs::module], #[hsrs::value_type], and #[hsrs::function], which then generate corresponding Haskell bindings. The process involves annotating Rust data types and functions, running the code generator, and importing the resulting Haskell module. The generated bindings handle memory management automatically via ForeignPtr, serialize complex types with Borsh, and convert common Rust types into idiomatic Haskell equivalents.
The tool supports a range of Rust types, including integers, booleans, enums, structs, and standard containers like Vec and Option. It also maps Rust Result and String types to Haskell’s Either and Text respectively, ensuring idiomatic Haskell code. The setup requires adding hsrs as a dependency on both Rust and Haskell sides, with minimal additional dependencies, primarily relying on Borsh serialization.
Why It Matters
This development matters because it simplifies the process of integrating Rust libraries into Haskell projects by automating the creation of safe, idiomatic bindings. It reduces boilerplate, minimizes errors related to manual FFI coding, and leverages Borsh serialization for efficient data transfer. For developers working on cross-language systems, Hsrs could accelerate development and improve reliability.
Haskell Rust FFI bindings generator
As an affiliate, we earn on qualifying purchases.
As an affiliate, we earn on qualifying purchases.
Background
Cross-language bindings between Rust and Haskell have traditionally required manual FFI coding, which is error-prone and often verbose. Recent efforts have focused on automating parts of this process, but Hsrs appears to be one of the first tools to combine annotation-based code generation with robust serialization support via Borsh. The announcement follows broader trends toward safer, more ergonomic FFI solutions in systems programming.
“Call Rust from Haskell with type-safe, automatically generated FFI bindings. Annotate your Rust types and functions, run the code generator, and get idiomatic Haskell that handles memory management, serialization, and type conversions for you.”
— Hacker News user ‘harmont-dev’
“Hsrs supports a range of Rust types and maps them to idiomatic Haskell types, with serialization handled automatically via Borsh.”
— Hacker News user ‘harmont-dev’

Celebration (The Oxford Organ Library)
As an affiliate, we earn on qualifying purchases.
As an affiliate, we earn on qualifying purchases.
What Remains Unclear
It is not yet clear how widely adopted Hsrs will become or how it performs with complex Rust projects. Details about long-term stability, performance benchmarks, and integration with existing build systems remain to be seen. Additionally, support for 32-bit platforms and other serialization formats is still unspecified.
ForeignPtr memory management Haskell
As an affiliate, we earn on qualifying purchases.
As an affiliate, we earn on qualifying purchases.
What’s Next
Next steps include broader testing by the developer community, potential integration into larger Rust and Haskell projects, and feedback on usability. Future updates may expand supported features, improve performance, and enhance documentation.
Rust to Haskell cross-language integration tools
As an affiliate, we earn on qualifying purchases.
As an affiliate, we earn on qualifying purchases.
Key Questions
How easy is it to integrate Hsrs into an existing Rust project?
Integration involves annotating your Rust code with provided macros, running the code generator, and importing the generated Haskell module. The process is designed to be straightforward with minimal setup.
Does Hsrs support all Rust types and features?
Hsrs supports common primitive types, enums, structs, and standard containers like Vec and Option. Support for advanced features or complex types may require additional work or future updates.
What serialization method does Hsrs use?
Hsrs uses Borsh serialization by default, which is efficient and suitable for many use cases. Support for other serialization formats has not been specified.
Is Hsrs compatible with 32-bit platforms?
Currently, platform notes indicate support is optimized for 64-bit platforms, mapping usize and isize to 64-bit types. Support for 32-bit systems is not yet confirmed.
Source: Hacker News