Created
June 4, 2015 15:58
-
-
Save notogawa/2bf5374424e3e51d3ced to your computer and use it in GitHub Desktop.
Call Python interpreter from Haskell using inline-c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE QuasiQuotes #-} | |
{-# LANGUAGE TemplateHaskell #-} | |
{-# LANGUAGE OverloadedStrings #-} | |
module Main where | |
import qualified Language.C.Inline as C | |
import Foreign.C.Types | |
import Foreign.C.String | |
C.include "python2.7/Python.h" | |
pyInterpret :: String -> IO () | |
pyInterpret code = withCString code $ \c -> | |
[C.block| void { | |
Py_Initialize(); | |
PyRun_SimpleString($(char *c)); | |
Py_Finalize(); | |
}|] | |
main :: IO () | |
main = getContents >>= pyInterpret |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment