Skip to content

Instantly share code, notes, and snippets.

@notogawa
Created June 4, 2015 15:58
Show Gist options
  • Save notogawa/2bf5374424e3e51d3ced to your computer and use it in GitHub Desktop.
Save notogawa/2bf5374424e3e51d3ced to your computer and use it in GitHub Desktop.
Call Python interpreter from Haskell using inline-c
{-# 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