The Fay compiler is a simple way to build fairly comprehensible javascript code from Haskell source.
It occurs to me that it should be rather easy to modify Fay to emit perl code rather than javascript. This would allow contributing things like plugins to various perl programs, without writing perl.
Of course, the same idea could probably be used to compile Haskell to other languages like python, but perl seems particularly well suited as a second Fay target, since javascript and it have quite similar syntax and similar support for features like closures which Fay relies on.
I do not have time to work on this idea myself. It would be a good project for a beginning Haskell programmer. You probably don't even need to fully understand monads to do it! Essentially, look at Fay output examples, translate them from javascript to perl, and then much of the code changes in Fay would probably be in simple string generation code.
I will forward any bitcoins sent to the address 149eBtWS6i8cwQdPQJJ8hAGpDuEqNidyTj to whoever makes this. If it doesn't happen in 1 year, any donations will be forwarded to the EFF instead.
Cool idea! I'd be happy to help if anyone wants to do this for elisp or perl (i use emacs, so elisp sounds awesome). I think this would work best as a separate package for maintenance purposes but I'd help out with making the changes needed in Fay to get that working.
It should be a matter of replacing the custom JS AST we're using for a perl AST and then generating code for that. Or maybe it could even use the JS AST and just print it differently? I forgot all my perl so I'm not sure if everything we're using can be translated on the printing level.
Here's an attempt at manually compiling this haskell code:
As perl:
I think that's fairly similarly to how Fay works, although it's been a while since I looked at Fay.
The use of thunk() gets us laziness. The implementation of force() needs some trickiness to avoid blowing the perl stack (perhaps using goto), since it may need to repeatedly force a thunk that yields a thunk, as happens with "force(putStrLn($s))".
Perl's GC can't handle cyclic data structures (can javascript's?). In f(), $d captures the input value, and it will remain referenced until the returned list is freed. But, there's no cyclic data structure at the perl level, just a list object consisting of $d and a thunk (which consists of a reference to f() and $d). So, I think perl's GC can handle that.