first shaky prototype on its feet 2
mwotton@ubuntu-vm:/mnt/hgfs/projects/rhaskell/linux$ cat rubytest.rb require 'dl/import' module HaskyPants extend DL::Importable dlload "./libdynhs.so" extern "int fibonacci_hs(int)" end puts HaskyPants.fibonacci_hs(12) mwotton@ubuntu-vm:/mnt/hgfs/projects/rhaskell/linux$ ruby rubytest.rb 144
So, maybe this doesn't look so terribly clever, but this is a ruby process calling a Haskell function, more or less transparently. The Haskell function is built into a dynamic library using John Meacham's jhc compiler. jhc happily produces some C code that with some very minimal massaging (renaming of main to dontusethis_main) can be built with gcc into a dynamic library.
Ruby/DL can then load the library file into a ruby practice, and there we have it: a minimal, half-arsed, dodgy ruby-haskell bridge, as promised. I'll polish the code up a bit and chuck it on github tonight or tomorrow.
There's a lot left to do. It'd be nice to import this into RubyInline or something similar, so you can write Haskell code directly in your Ruby files. Also, currently you have to list the functions that you want to export from Haskell as well as the functions you want to import into Ruby, which is at least one too many times and possibly two: arguably, anything at the top level is intended to be imported, especially in an inline context. It'd also be great to have it work with compilers other than jhc: jhc is still a bit of a bear to install, and recompilation of big files is very slow. Still, this is a very encouraging spike.
Edit: it's now called Hubris, and you can get the extremely minimal code from http://github.com/mwotton/Hubris/tree/master
Question: have you considered using Ruby’s FFI? Would allow your program to work with other Ruby impls like JRuby.
Murphee: I did look into it, but found I didn’t need the level of sophistication they had, given that I’ve got to do all my own unpacking and checking on the Haskell side anyway. It’s certainly an option further down the track when the project’s a bit more mature.