'Compiling' expression graph into Arrows

Hello, I have a graph of function applications which I would like to 'compile' into an Arrow, specifically the SF Arrow from Yampa. I'd appreciate any advice on how I might go about this. The graphs, of which there will be many, will be constructed at runtime and will be executed for extended periods of time so execution time will dominate compilation time. The graphs might also need to be passed around and executed 'elsewhere', where 'elsewhere' will almost certainly be the same GHC version but maybe on different architectures. The hand-written 'compilation' in the attached file gives a rough idea of what I start with and what I need to end up with. I could just automate the hand-written process by generating the SFs and arrow-syntax blocks, write them into a file then call GHC... seems a bit cowboyish. Or, write the graph into a template file that has Template Haskell to generate the SFs and arrow-syntax blocks then call GHC... almost as cowboyish? Or, fold the graph up using loop and arr... probably the simplest, once I get rid of my sugar dependency and figure out how to use loop that is ;). Or, maybe I can actually get the expression graph into a GHC api representation somehow and let it work marvels of optimisation on the expression before turning it into an arrow. Any idea on the relative merits of these, or other ideas? Can GHC optimise arrow code much during compilation, or will code folded up at runtime using loop/arr be just as efficient? Could GHC condense the functions of multiple graph nodes into a single function for conversion to an SF arrow? Will the necessity of introducing delays rule out using GHC to simplify the raw expression? Thanks Daniel
participants (1)
-
Daniel McAllansmith