Show HN: Hsrs – Type-Safe Haskell Bindings Generator for Rust

· coding systems devtools · Source ↗

TLDR

  • Annotate Rust types with #[hsrs::*] macros, run hsrs-codegen, and get idiomatic Haskell FFI bindings with automatic memory management via ForeignPtr and Borsh serialization.

Key Takeaways

  • Three annotation types: data_type (opaque pointer), value_type (Borsh-serialized struct), enumeration (repr(u8) mapped to Word8 with pattern synonyms).
  • Type mappings are automatic: Result<T,E> becomes Either E T, Option<T> becomes Maybe T, Vec<T> becomes [T], String becomes Text.
  • Memory is handled via ForeignPtr newtypes with automatic cleanup; no manual free calls needed on the Haskell side.
  • usize/isize are hardcoded to Word64/Int64, so 32-bit platform targets may silently truncate values.
  • Both Rust and Haskell sides need the hsrs package; codegen is a separate hsrs-codegen cargo binary targeting a source .rs file.

Hacker News Comment Review

  • No substantive HN discussion yet.

Original | Discuss on HN