Producing fortran/C code with haskell?
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? V.
On Jan 30, 2004, at 1:32 PM, 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?
V.
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
You might try looking at http://www.fftw.org. They use an Objective Caml program to generate optimized C fourier transforms for various machine architectures. Best Wishes, Greg
On Fri, 30 Jan 2004 19:32:53 +0100 Vincenzo aka Nick Name <vincenzo_mlRE.MOVE@yahoo.it> 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?
Googling for "embedded domain specific compilers" should turn up links on one interesting technique to achieve this.
Strafunski might help? --- Derek Elkins <ddarius@hotpop.com> wrote:
On Fri, 30 Jan 2004 19:32:53 +0100 Vincenzo aka Nick Name <vincenzo_mlRE.MOVE@yahoo.it> 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?
Googling for "embedded domain specific compilers" should turn up links on one interesting technique to achieve this.
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
===== Christopher Milton cmiltonperl@yahoo.com
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<imax...) { out[i][j][k] = f[i][j][k] + g[i]; if (a) out[i][j][k] += x; if (b) out[i][j][k /= y[i][j][k]; } but for speed reasons you need to put the if (a) and if (b) on the outside of the loop, but you don't want to code each case by hand, since that would create an unmaintainable mess. In my framework, the above would be accomplished (creating four separate loops for all combinations of a and b) by something like whether_or_not "a" $ whether_or_not "b" $ do_block "for (int i=0;i<imax...)" [doexp "out[i][j][k] = f[i][j][k] + g[i]", if_ "a" $ doexp "out[i][j][k] += x", if_ "b" $ doexp "out[i][j][k] /= y[i][j][k]" ] There are also features relating to expressions, which can simplify arithmetic for cases where a variable is known to be one or zero. But in general, it's an ugly piece of code... -- David Roundy http://www.abridgegame.org
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?
A possibly useful resource is: My cross-module inliner for C contains a bunch of type definitions to represent C code, a pretty-printer, a C parser (which supports al the gcc extensions) and various useful libraries (e.g., generate dependency graph, estimate size of generated code, etc.) It is GPLed, the code for manipulating C is clearly separated from the application that uses it. You can get it from: http://www.cs.utah.edu/flux/knit/cmi.html -- Alastair Reid haskell-consulting.com
participants (6)
-
Alastair Reid -
Christopher Milton -
David Roundy -
Derek Elkins -
Gregory Wright -
Vincenzo aka Nick Name