Skip to content
Toy example of calling Rust from Haskell
Haskell Rust Makefile
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
LICENSE
Makefile Updated with more test information Jan 13, 2015
README.md Updated documentation, as it no longer uses unstable features and als… Jun 10, 2015
fact.rs git-ified current state Jan 13, 2015
main.hs
point.rs Updated point.rs for Rust 1.0 release Jun 10, 2015

README.md

Rust-Haskell FFI Example

A lot of Haskell people I've talked to are excited about the prospect of using Rust as a replacement for C in certain speed-critical or low-level parts of their application. To that end, and in light of the recent (as of this writing) Rust 1.0 alpha release, I've shown here a small example of calling Rust from Haskell.

This contains a single Haskell file and two Rust libraries which Haskell can call out to. The first Rust library is contained in fact.rs and implements a simple factorial, which is easier to wrap; the second is contained in point.rs and demonstrates allocating memory in Rust, passing it to Haskell, using wrapped Rust functions to manipulate it, and finally allowing Haskell's GC to call back into Rust to free it.

This of course requires GHC and a reasonably recent version of rustc installed. This version has been tested with GHC versions 7.8.4 and 7.10.1, and the following rustc versions:

1.0.0 (a59de37e9 2015-05-13) (built 2015-05-14)

All the examples here I release into the public domain.

You can’t perform that action at this time.