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

Dan Weston westondan at imageworks.com
Thu Mar 27 14:19:24 EDT 2008

I notice that you omit from the advantages of calling Haskell from 
Python what I consider the most important reason of all (at least from 
the Haskell community side).

The choice of programming language (at least at the top level) is 
primarily a political or managerial choice, not a technical one. Python 
is not merely a "terrific glue language", it is often the "blessed" 
language, and currently the language of choice in some industries, 
including my own. This is not just "glue code" either: one in-house 
application has about 100,000 lines of Python code (calling a comparable 
amount of C++ code)!

Any hope of introducing Haskell into this realm requires a way to work 
Haskell in slowly and from the bottom. As such I view your proposed 
project as quite valuable, a robust and easy-to-use Python-Haskell 
bridge (Python on top) being essential to growing the presence of 
Haskell in non-academic circles.

Of course, it may be for this very political reason that you have 
omitted the above from your list, in which case I completely understand. :)


Michał Janeczek wrote:
> 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
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe

More information about the Haskell-Cafe mailing list