[Haskell-cafe] Re: [Haskell] ANNOUNCE: CPython / libpython bindings

John Millikin jmillikin at gmail.com
Mon Dec 28 13:01:15 EST 2009


On Mon, Dec 28, 2009 at 03:52, Yitzchak Gale <gale at sefer.org> wrote:
> John Millikin wrote:
>> It has only a minimal binding to libpython, enough to implement
>> its class instances but not enough for general-purpose use of
>> libpython.
>
> I'm not sure what you mean by that. Using MissingPy, you can
> instantiate a Python object of any type, marshall data back and
> forth between Python and Haskell for the basic built-in Python
> types and any object built out of them, access any Python
> module, and call any Python function or method. Most people
> find those capabilities to be quite good for general-purpose use.
> What do you feel is missing?

http://docs.python.org/3.1/c-api/init.html
http://docs.python.org/3.1/c-api/reflection.html

Most of http://docs.python.org/3.1/c-api/concrete.html
Most of http://docs.python.org/3.1/c-api/abstract.html

While it is possible to emulate some C API procedures using Python
encoded in Haskell, I find the C API more readable. Compare:

---------------------------------------------------------
-- emptySet :: IO Set

callArgs (getItem (getAttribute (importModule "types") "__builtins__")
"set") [] >>= fmap fromJust cast
toList [] >>= iterableToSet
---------------------------------------------------------

And of course, it's very difficult to do things like create a new
interpreter or modify the "sys" module from within a running
interpreter.

>> I wrote this package so I could benchmark Python modules using
>> Criterion, with an eye towards writing extension modules in Haskell,
>> so it has many more data types and computations available.
>
> Oh, you want to write Python extension modules in Haskell?
> Right, MissingPy explicitly does not cover calling Haskell
> from Python.

Eventually -- Python 3 improved the module system enough that it
should be possible (compared to 2.x, where C-style static memory was
essentially required). I'd like to try (for example) implementing the
Python "decimal.Decimal" type in terms of Haskell's Ratio.

> For accessing Python from Haskell, though, MissingPy has
> been around for a long time and works well. There may be
> quite a lot of code around that uses it. Is your API similar?
> Is there any specific new capability that you are adding?
> Do you have some compatibility recommendations?

My API's not similar -- one of my goals was to match the C API as
closely as is reasonable, with more type safety.

According to the reverse dependency-enabled Hackage[1], as of December
24[2] there are no dependencies on MissingPy. In contrast, there are
27 direct and 17 indirect dependencies on MissingH.

[1] http://bifunctor.homelinux.net/~roel/cgi-bin/hackage-scripts/package/MissingPy
[2] http://bifunctor.homelinux.net/~roel/hackage/packages/archive/recent.html


More information about the Haskell-Cafe mailing list