I want to announce first release of inline-python. It’s inspired by inline-r
and allows to embed python snippets which can capture values including haskell function from outside scope. For example:
{-# LANGUAGE QuasiQuotes #-}
import Python.Inline
import Python.Inline.QQ
main :: IO ()
main = withPython $ do
let input = [1..10] :: [Int]
let square :: Int -> IO Int
square x = pure (x * x)
print =<< runPy $ do
fromPy' @[Int] =<< [pye| [ square_hs(x) for x in input_hs ] |]
python variables ending in _hs
are captured from outside scope. Python’s list then converted back to haskell so program would print:
[1,4,9,16,25,36,49,64,81,100]
This is alpha quality software so one shouldn’t get surprised by memory leaks, deadlocks, segfaults and things not working in general.