haskell - Gakgu/Gakgu.github.io GitHub Wiki
μμ ν¨μν μΈμ΄.
λ€μ 3κ°μ μμ νμΌμ μμ±ν ν λΉλνλ©΄ λλ€.
-
hello.hs
module Hello where foreign export ccall add :: Int -> Int -> Int foreign export ccall multiply :: Int -> Int -> Int add :: Int -> Int -> Int add x y = x + y multiply :: Int -> Int -> Int multiply x y = x * y
-
main.cpp
#include <iostream> #include "hello_stub.h" using namespace std; int main(int argc, char** argv) { hs_init(&argc, &argv); cout << "3 + 7 = " << add(3, 7) << endl; cout << "3 * 7 = " << multiply(3, 7) << endl; hs_exit(); return 0; }
-
Makefile
build : hello.o main.o ghc -no-hs-main -o main main.o hello.o -lstdc++ main.o: g++ -c main.cpp -I/usr/lib/ghc-8.6.4/include hello.o: ghc -c hello.hs clean: rm hello.hi \ hello.o \ hello_stub.h \ main.o \ main