
On Fri, Jan 30, 2004 at 07:32:53PM +0100, Vincenzo aka Nick Name wrote:
I seem to recall a discussion, don't know if it was here or on comp.lang.functional, where somebody said he uses haskell to generate fortran code.
That fascinated me a lot, because that would mean being able to generate a program already specialized for a specific input, by first reading input in haskell and then producing code (fortran, but could be C either) - and because I guess it can add static safety exploiting haskell types. Since we already have that nice syntax for monads those programs should be readable, too.
Where could I find information on such topics, or existing libraries to generate programs with haskell? Is somebody willing to share what (s)he already did?
I've used haskell to generate C code for a few inner loops. You can browse
my code at the following link:
http://jdj5.mit.edu/cgi-bin/darcs?meep*
The haskell code is all in the hsrc directory, and StepGen.lhs is the
module that does the work, assisted a bit by Complex.lhs and
YeeLattice.lhs, which define stuff releting to complex numbers and the Yee
lattice respectively. The files step_d_gen.hs, etc., each create a program
whose output is a chunk of C++ code that is then #included into the
relevant function.
My code is ugly and not very general at all, but it has allowed me to
cobble together something that generates the inner loop in something
resembling a reasonable manner. The main problem the code tries to solve
is situations where you'd like to code
for (int i=0;i