口粮:
{-# LANGUAGE ForeignFunctionInterface #-}
import GHC.Ptr
import Foreign
import Foreign.C
import Control.Monad
foreign import ccall unsafe "fibonacci.c fib" c_fib :: Int -> Int
example :: IO ()
example =
print (c_fib 5)
main = example
斐波那契
int fib(const int n) {
if (n == 1) {
printf("here");
return 1;
}
else {
return n*fib(n-1);
}
}
结果:
120 // does not print "here"
到底是怎么回事?