14 Commits

Author SHA1 Message Date
George Thomas
71e4ffaede Make Rust tree type polymorphic 2026-02-19 21:28:00 +00:00
George Thomas
ca063b1dd6 Rename tree types 2026-02-19 21:11:58 +00:00
George Thomas
261acca8a4 Define nicer Rust tree type and coerce 2026-02-19 21:11:23 +00:00
George Thomas
55a781eeb8 Add tree example 2026-02-19 20:44:04 +00:00
George Thomas
06767e17ea Add newline for consistency 2026-02-19 19:37:46 +00:00
George Thomas
9ca4f615d8 Use simpler tagged union translation
Avoids the worst part of the header hack, and makes Haskell wrapper simpler.
2026-02-19 17:22:15 +00:00
George Thomas
5019af701f Mark pure function 2026-02-19 17:22:15 +00:00
George Thomas
5907a064a7 Use fixed-width integers
Even though `Int` and `isize` should be the same in practice, we can't cleanly convert, as the type information isn't quite there. And anyway, strictly speaking per the report, `Int` is only guaranteed to hold 30 bits.

Note that this is essentially unchanged even if we specify `usize_is_size_t = true` for `cbindgen`.
2026-02-19 17:19:28 +00:00
George Thomas
024b6aec87 Implement function with return value 2026-02-19 16:29:52 +00:00
George Thomas
97a4f1c359 Disable dead code warning for whole Rust file 2026-02-19 16:29:52 +00:00
George Thomas
13b9324bc4 Simplify use sites by passing by value 2026-02-19 16:29:52 +00:00
George Thomas
7e09c1d681 Add more complex data types 2026-02-19 16:29:52 +00:00
George Thomas
0a1911862f Expose explicit C interface
We drop the tools specifically designed for Haskell and Rust together, in favour of general tools for using each with C.

Namely, we use Mozilla's `cbindgen` for generating header files from the Rust source, and Well-Typed's new `hs-bindgen` tool for generating Haskell from those header files.

The Rust code here is essentially the result of expanding the old macro, then inlining and renaming internals.

The most important thing here is that we're now relying solely on robust well-maintained tools.
2026-02-19 16:29:41 +00:00
George Thomas
7bb41f6825 Call Rust from Haskell with cargo-cabal and hs-bindgen
See https://sraka.xyz/posts/hs-bindgen-introduction.html.

For now, this is a shell-based workflow, rather than using Nix to build everything, i.e. `nix develop` works but `nix build` doesn't. And `cargo build` has to be called manually to create the C library, rather than `cabal` being clever enough to invoke it itself.

We ran `cargo cabal init` from the `rust` directory (`nix shell github:yvan-sraka/cargo-cabal`), which generated `hsbindgen.toml` (which we use), and `Setup.lhs` (which just added `extra-lib-dirs`, and with the wrong paths, so we dspecify those statically instead in `garnet.cabal`). We also follow its advice to use `staticlib`.

Also, after we ran the first `cargo build` (requiring a `mkdir rust/src` before it would run), we took the generated the Haskell file, and moved the main contents in to `Main.hs` manually.
2026-02-19 13:57:14 +00:00