blob: 7896e491cbe7b0de99ee66c74cdcd4267f7bfbdd (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
{-# LANGUAGE ForeignFunctionInterface #-}
{-# LANGUAGE TemplateHaskell #-}
import Language.Haskell.TH.Syntax
import System.IO (hFlush, stdout)
foreign import ccall foo :: Int -> IO Int
do fpIn <- addTempFile "c"
let cSrc = (unlines [ "#include <stdio.h>"
, "int foo(int x) {"
, " printf(\"calling f(%d)\\n\",x);"
, " fflush(stdout);"
, " return 1 + x;"
, "}"
])
runIO $ writeFile fpIn cSrc
addForeignFilePath LangC fpIn
return []
main :: IO ()
main = do
foo 2 >>= print
hFlush stdout
|