[Haskell-cafe] Re: SoC project: Python-Haskell bridge - request for feedback

Michał Janeczek janeczek at gmail.com
Thu Mar 27 01:00:16 EDT 2008


Hi,

This is my second take on the project proposal.
I have expanded on a few points, and hopefully
also clarified a little bit.

Please comment :)

Regards,
Michal


Python-Haskell bridge
=====================

Description
-----------

This project will seek to provide a comprehensive, high level (and thus
easy to use) binding between Haskell and Python programming languages.
This will allow using libraries of either side from each language.

If we decide to support function callbacks, these two functionalities
(embedding Haskell in Python, and vice versa) become interrelated.
In this light, it makes sense to implement them in the scope of the
same project.


Advantages of calling Haskell from Python
-----------------------------------------

* Robust components

    It might be beneficial to implement safety-critical componenets
    in a strongly, statically typed language. Since Python itself is
    a terrific "glue language", such components would usually be purely
    functional, leaving IO to the Python side.
    Embedding Haskell code in this way is of particular interest when
    there already is a large existing Python infrastructure. One can
    implement new functionality in a form of Haskell plugin/component,
    even if complete rewrite is not feasible.

* Performance improvements for speed-critical code

    Haskell compiled to native code is typically an order of magnitude
    faster than Python. Aside from that, advanced language features
    (such as multicore parallel runtime, very lightweight threads
    and software transactional memory) further serve to improve the
    performance. Haskell could become a safe, high level alternative
    to commonly used C extensions.

* Access to sophisticated libraries

    While its set of libraries is not as comprehensive as that of
    Python, Haskell can still offer some well tested, efficient
    libraries. Some of the examples might be:

    * rich parser combinator libraries (like Parsec)
    * persistent, functional data structures (i.e. Data.Map,
          Data.IntMap, Data.Sequence, Data.ByteString)
    * QuickCheck testing library to drive analysis of Python code


Advantages of calling Python from Haskell
-----------------------------------------

* Python as a scripting language for Haskell applications

    Python is widely considered to be more approachable for regular
    users. As such, it could be used as a configuration/extension
    language for applications that benefit from extra flexibility.
    One example of such application is xmonad window manager.

* Access to a large number of libraries

    As a much more popular language, Python has built up an impressive
    suite of libraries. There already are Haskell projects which rely
    on Python code to implement missing functionality, for example
    a paste bin application hpaste, which uses Pygments syntax coloring
    library.


Deliverables
------------

* A low level library to access and manage Python objects from Haskell

* Library support for wrapping Haskell values in Python objects. This
  is necessary to allow function callbacks. In addition, thanks to that
  feature large and/or lazy data structures can be efficiently passed
  from Haskell to Python

* A set of low level functions to convert built-in data types between
  Haskell and Python (strings, numbers, lists, dictionaries,
  generators etc.)

* A high level wrapper library for Haskell that simplifies embedding
  and calling Python code

* A set of functions, and possibly a tool, to wrap up monomorphic
  functions and expose them to Python through foreign export facility

* A way (an external tool, or a Template Haskell macro) to easily
  derive conversion functions for user-defined data types/objects

* Documentation and a set of examples for all of above


Optional goals
--------------

In order of increasing amount of work and decreasing priority:

* Exporting a wider class of functions to Python

* A Python module that inspects a compiled Haskell module and
  transparently exposes functions within. This might be possible
  thanks to GHC API


More information about the Haskell-Cafe mailing list