diff --git a/haskell-to-rust/Cargo.toml b/haskell-to-rust/Cargo.toml new file mode 100644 index 0000000..763b4d9 --- /dev/null +++ b/haskell-to-rust/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "haskell-to-rust" +version = "0.1.0" +authors = ["Bill Murphy "] + +[lib] +name = "double_input" +crate-type = ["dylib"] diff --git a/haskell-to-rust/Makefile b/haskell-to-rust/Makefile new file mode 100644 index 0000000..23e15a2 --- /dev/null +++ b/haskell-to-rust/Makefile @@ -0,0 +1,15 @@ +ifeq ($(shell uname),Darwin) + EXT := dylib +else + EXT := so +endif + +all: target/debug/libdouble_input.$(EXT) + ghc src/Main.hs target/debug/libdouble_input.$(EXT) -o main + +target/debug/libdouble_input.$(EXT): src/lib.rs Cargo.toml + cargo build + +clean: + rm -rf target + rm src/*.o src/*.hi diff --git a/haskell-to-rust/main b/haskell-to-rust/main new file mode 100755 index 0000000..2d10333 Binary files /dev/null and b/haskell-to-rust/main differ diff --git a/haskell-to-rust/src/Main.hs b/haskell-to-rust/src/Main.hs new file mode 100644 index 0000000..bb13723 --- /dev/null +++ b/haskell-to-rust/src/Main.hs @@ -0,0 +1,10 @@ +{-# LANGUAGE ForeignFunctionInterface #-} + +import Foreign.C + +foreign import ccall "double_input" doubleInput :: CInt -> CInt + +main = do + let input = 4 + let output = doubleInput input + putStrLn $ show input ++ " * 2 = " ++ show output diff --git a/haskell-to-rust/src/lib.rs b/haskell-to-rust/src/lib.rs new file mode 100644 index 0000000..7312f33 --- /dev/null +++ b/haskell-to-rust/src/lib.rs @@ -0,0 +1,4 @@ +#[no_mangle] +pub extern fn double_input(input: i32) -> i32 { + input * 2 +}