[Haskell-cafe] Haskell as an extension language

Yuri D'Elia wavexx at users.sf.net
Sun Sep 2 13:45:54 EDT 2007

Hello everyone;

I've been using haskell for quite some time now, but, as usual, I still 
find myself resorting to c code too much often due to the performance 
penalty introduced. FFI is all nice and dandy, yet, the need to compile 
the code and separate the implementation in two is a mayor development 
issue I'd like to eliminate along with batch compilation.

In the way I like to work, I only use the interpreter (I mainly started 
with this approach with ocaml); just program interactively; close the 
whole session and pretend to resume the work next time I reopen the 
interpreter. Unfortunately, the interpreted performance is, many times, 
not sufficient for my purposes.

In the past I've been coding several programs that would allow the user 
to extend the functionality at runtime through real c code. The "host" 
program itself could start an internal editor that accepted c code. The 
code would then be sent to the system compiler, generating a dynamic 
object that would be loaded in the current program (and executed) 
immediately. With some voodoo usage of "unexelf", I could create a 
simple runtime environment with very good performance (except for the 
initial compilation delay), interactivity and persistence, but, as you 
might expect, almost no resilience to errors and difficult debugging 

I would like to resume this idea. Programming the core (minimal) 
application in c and then adding an extension mechanism always led to 
better and faster programs in my experience than trying to use directly 
an higher-level language and (ab)use the various forms of FFI. UI 
latency was one of the primary reasons in many cases. The amount of c 
code needed was always lower too, in the end, as the code was extended 
beyond the original minimal requirements. The extensions, being wrapped 
around the core data structures, tended to be more specialized and 
concise than general all-purpose libraries.

Has anyone experienced similar situations? Is there some documentation 
about integrating an haskell interpreter in host programs that would 
allow session persistence and some minimal form of debugging? Which 
interpreter works better in this context?


More information about the Haskell-Cafe mailing list