SoC project: Python-Haskell bridge - request for feedback

Hi, I am a student interested in participating in this year's SoC. At http://tsk.ch.uj.edu.pl/~janeczek/socapp.html (and also below in this email) you can find a draft of my project proposal. I'd like to ask you to comment on it, especially the deliverables part. Are you interested in such a project, and if yes, what features would be most important to you? Is anything missing, or should something get more priority or attention? 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. Benefits for Python ------------------- * Robust, high assurance components It might be beneficial to implement safety-critical components in a strongly, statically typed language, using Python to keep them together. Cryptography or authentication modules can be an example. * 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 in improving 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. Examples might be rich parser combinator libraries (like Parsec) and persistent, functional data structures. QuickCheck testing library could also be used to drive analysis of Python code. Benefits for Haskell -------------------- The project would benefit Haskell by providing it with access to an impressive suite of libraries. It also has a potential to help Haskell adoption, by mitigating risk of using Haskell in a project. Deliverables ------------ * A low level library to access Python objects from Haskell * A set of low level functions to convert built-in data types between Haskell and Python (strings, numbers, lists, dictionaries, functions, generators etc.) * A higher level library allowing easy (transparent) access to Python functions from Haskell, and wrapping Haskell functions for Python to access * A way to easily derive conversion functions for user-defined data types/objects. Functions derived in such a way should work well with both low level and high level access libraries * Documentation and a set of examples for all of above Optional goals -------------- These are of lower priority, and might require a fair amount of work. I would like to implement most of them, if technically feasible. If they don't fit into Summer of Code timeframe, I am planning to finish afterwards. * A Python module for accessing functions from Haskell modules without manual wrapping (such wrapping should be already easy thanks to the high level library). It'd be accomplished through GHC api - if it allows it. The Haskell side of the high level library will already support such mode of operation * Extend and refactor the code, to make it support other similar dynamic languages. This is a lot of work, and definitely out of the scope of Summer of Code project, but some design decisions may be influenced by this. Related projects ---------------- They (and quite possibly some others) will be referenced for ideas. * MissingPy Provides a one way, low level binding to Python. Some of the code can be possibly reused, especially data conversion functions. It doesn't seem to export all features, in particular function callbacks are not supported * HaXR XML-RPC binding for Haskell. It could provide inspiration for reconciling Haskell and Python type systems, resulting in a friendly interface * rocaml A binding between Ruby and OCaml

Hello Michal, Monday, March 24, 2008, 11:38:07 PM, you wrote:
Python-Haskell bridge
seems interesting
Benefits for Haskell
you forget about ability to use Python as scripting language inside Haskell programs. look at HsLua library as example of this -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com

Bulat Ziganshin wrote:
Hello Michal,
Monday, March 24, 2008, 11:38:07 PM, you wrote:
Python-Haskell bridge
seems interesting
This is indeed interesting for those (like me) wanting to introduce Haskell stealthily into a Python-based facility: essentially, leave the IO monad in Python but invoke non-IO Haskell functions.
Benefits for Haskell
you forget about ability to use Python as scripting language inside Haskell programs. look at HsLua library as example of this
This is much less interesting for those (like me) who, once in Haskell, don't feel the least inclined to go back to Python. Missing libraries in Haskell (for my applications) are usually also missing in Python and need FFI to some (usually numeric) library written in C/C++ anyway. Why do data marshalling twice? Dan

Hello Dan, Tuesday, March 25, 2008, 1:29:51 AM, you wrote:
you forget about ability to use Python as scripting language inside Haskell programs. look at HsLua library as example of this
This is much less interesting for those (like me) who, once in Haskell, don't feel the least inclined to go back to Python. Missing libraries in Haskell (for my applications) are usually also missing in Python and need FFI to some (usually numeric) library written in C/C++ anyway. Why do data marshalling twice?
Python, unlike Haskell, can be compiled on the fly -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com

westondan:
Bulat Ziganshin wrote:
Hello Michal,
Monday, March 24, 2008, 11:38:07 PM, you wrote:
Python-Haskell bridge
seems interesting
This is indeed interesting for those (like me) wanting to introduce Haskell stealthily into a Python-based facility: essentially, leave the IO monad in Python but invoke non-IO Haskell functions.
Yes, exactly. The Haskell risk is mitigated, and you can use it exactly as you wish, for strongly typed, purely functionaly, robust components held together with Python glue. And then its easier to sneak Haskell into an existing python toolchain.
Benefits for Haskell
you forget about ability to use Python as scripting language inside Haskell programs. look at HsLua library as example of this
This is much less interesting for those (like me) who, once in Haskell, don't feel the least inclined to go back to Python. Missing libraries in Haskell (for my applications) are usually also missing in Python and need FFI to some (usually numeric) library written in C/C++ anyway. Why do data marshalling twice?
Agreed. There are some libraries we don't have (pygments is one). -- Don

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

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. :) Dan 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@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

Remember that there are two proposals here, one potentially to the Python team, one to the Haskell team . Of course the Haskell guys are strongly interested in the use case Dan describes -- mitigating risk by using Haskell for small components first, as part of larger legacy systems. The Python guys are more interested in Python use from Haskell, by the looks of it. -- Don westondan:
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. :)
Dan
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@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

FWIW, my MissingPy project accomplishes part of this (calling Python
from Haskell) already.
-- John
On 2008-03-27, Dan Weston
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).

I did not see MissingPy on Hackage (presumably it would be next to MissingH?) I found it (listed on http://www.complete.org/jgoerzen/softindex.html) at http://darcs.complete.org/missingpy Is this the right place to get it? Dan John Goerzen wrote:
FWIW, my MissingPy project accomplishes part of this (calling Python from Haskell) already.
-- John
On 2008-03-27, Dan Weston
wrote: 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).
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

On Thursday 27 March 2008 04:07:23 pm Dan Weston wrote:
I did not see MissingPy on Hackage (presumably it would be next to MissingH?)
I found it (listed on http://www.complete.org/jgoerzen/softindex.html) at http://darcs.complete.org/missingpy
Is this the right place to get it?
Yes, it is. I have not had the need for it lately, and thus haven't made recent releases to upload to Hackage. It did work solidly when I used it, so hopefully it can be at least some value to someone. -- John

On 2008.03.27 14:07:23 -0700, Dan Weston
I did not see MissingPy on Hackage (presumably it would be next to MissingH?)
Remember, Hackage is alphabetical by category and then by title; I personally would not stick MissingH in the Unclassified category but something like Development. Anyway, I doubt you'll see MissingPy on Hackage soon; note that the installation procedure requires you to use a python script to generate an appropriate cabal file. (It doesn't build for me anyway, but that's a separate issue.)
I found it (listed on http://www.complete.org/jgoerzen/softindex.html) at http://darcs.complete.org/missingpy
Is this the right place to get it?
Dan
I think so. That's the host I recognize from HSH, at least. -- gwern Brown virtual DDR&E B83 Kwajalein Team IMF CANSLO Watergate MOD

Oh, I thought I added that as "related work" to the ticket page. If its not, couldyou add it? jgoerzen:
FWIW, my MissingPy project accomplishes part of this (calling Python from Haskell) already.
-- John
On 2008-03-27, Dan Weston
wrote: 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).
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

On Thu, Mar 27, 2008 at 8:27 PM, John Goerzen
FWIW, my MissingPy project accomplishes part of this (calling Python from Haskell) already.
-- John
Yes, MissingPy was mentioned in the original project description, and I have hopes of reusing substantial parts of it. I'd like to make it more comprehensive (in particular, have it support higher order functions when calling Python code), and possibly also easier/more transparent to use. And there of course comes the second side of the project, calling Haskell from Python Regards, Michal
participants (6)
-
Bulat Ziganshin
-
Dan Weston
-
Don Stewart
-
gwern0@gmail.com
-
John Goerzen
-
Michał Janeczek