Merge pull request #9 from billpmurphy/master
add Haskell to Rust example
This commit is contained in:
8
haskell-to-rust/Cargo.toml
Normal file
8
haskell-to-rust/Cargo.toml
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
[package]
|
||||||
|
name = "haskell-to-rust"
|
||||||
|
version = "0.1.0"
|
||||||
|
authors = ["Bill Murphy <billpmurphy92@gmail.com>"]
|
||||||
|
|
||||||
|
[lib]
|
||||||
|
name = "double_input"
|
||||||
|
crate-type = ["dylib"]
|
||||||
16
haskell-to-rust/Makefile
Normal file
16
haskell-to-rust/Makefile
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
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 main
|
||||||
|
rm src/*.o src/*.hi
|
||||||
10
haskell-to-rust/src/Main.hs
Normal file
10
haskell-to-rust/src/Main.hs
Normal file
@@ -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
|
||||||
4
haskell-to-rust/src/lib.rs
Normal file
4
haskell-to-rust/src/lib.rs
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
#[no_mangle]
|
||||||
|
pub extern fn double_input(input: i32) -> i32 {
|
||||||
|
input * 2
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user