Skip to content

Add Haskell bindings for oxbitnet (Issue #8)#28

Merged
m96-chan merged 2 commits intomainfrom
haskell-bindings
Mar 8, 2026
Merged

Add Haskell bindings for oxbitnet (Issue #8)#28
m96-chan merged 2 commits intomainfrom
haskell-bindings

Conversation

@m96-chan
Copy link
Owner

@m96-chan m96-chan commented Mar 6, 2026

Summary

  • Add Haskell bindings wrapping oxbitnet-ffi via hsc2hs for correct cross-platform struct layout
  • High-level API (OxBitNet module) with MVar + bracket for thread-safe resource management, IO Bool token callbacks, and typed exceptions
  • Low-level FFI module (Foreign.OxBitNet.Raw) with Storable instances, callback wrappers, and safe/unsafe FFI imports
  • Interactive chat REPL example (oxbitnet-chat)
  • CI: version check for oxbitnet.cabal + publish-hackage job (GHC 9.6, Cabal 3.10, source-only Hackage upload)

Design decisions

  • MVar (Maybe (Ptr OxBitNet)) instead of ForeignPtroxbitnet_free blocks (tokio runtime shutdown), unsafe on GC finalizer thread
  • safe FFI for load/generate/chat (long-running + callbacks); unsafe for free/error_message/defaults
  • Token callback returns IO Bool (True = stop) — more idiomatic Haskell than Int32
  • Logger FunPtr intentionally leaked (process-lifetime, matching C API contract)
  • Source-only Hackage distribution — user links against their local liboxbitnet_ffi

Test plan

  • cargo build -p oxbitnet-ffi --release then cabal build all
  • Run oxbitnet-chat with a GGUF model, verify streaming output + progress
  • Verify freeBitNet / bracket cleanup
  • Verify CI version check parses oxbitnet.cabal correctly

Closes #8

🤖 Generated with Claude Code

m96-chan and others added 2 commits March 6, 2026 16:30
Wrap the oxbitnet-ffi C API via Haskell's FFI (hsc2hs) for type-safe,
cross-platform struct layout. High-level API uses MVar + bracket for
thread-safe resource management, with IO Bool token callbacks for
idiomatic early stopping.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Keep both C# (NuGet) and Haskell (Hackage) CI jobs and version checks.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@m96-chan m96-chan merged commit dba829e into main Mar 8, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Haskell bindings (oxbitnet-haskell)

1 participant