<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META NAME="Generator" CONTENT="MS Exchange Server version 6.5.7654.12">
<TITLE>RE: [Haskell-cafe] compilation to C, not via-C</TITLE>
</HEAD>
<BODY>
<!-- Converted from text/plain format -->

<P><FONT SIZE=2>Hi Ryan,<BR>
<BR>
Nice to hear from another games industry coder on the Haskell lists :)<BR>
<BR>
Thanks, this is exactly the kind of detail I was after. I had heard rumours of the Evil Mangler but hadn't found a concrete reference to it before. This makes a lot of sense. Given this and the other helpful comments I tend to agree with Wren that a different compiler might be a better starting point. I'll follow up JHC and YHC in more depth and have a nose at Timber and Gambit-C as well.<BR>
<BR>
I'm pretty much undecided on whether haskell and games are going to play well at the moment. For me, it's very difficult to call, but I think it still looks interesting enough to pursue. I note there is at least a precedent set for functional languages in games by Naughty Dog's GOAL (<A HREF="http://en.wikipedia.org/wiki/Game_Oriented_Assembly_Lisp">http://en.wikipedia.org/wiki/Game_Oriented_Assembly_Lisp</A>). As it happens, I tried to stir up the coders on the gd-algorithms mailing list recently to see how much interest there was in Haskell for games. There was a fair amount of cyber-tumbleweed :). Please feel free to chip in :)<BR>
<BR>
I agree the runtime is definitely where a big chunk of the problem is - particular garbage collection - but incidentally this is the bit I'm least worried about. It's all work, but I think there are ways of managing this predictably and efficiently. The 'clump and dump' approach the Eaton guys have used (and maybe region marking in JHC?) was one idea that had sprung to mind already - assuming it's the same one :).<BR>
<BR>
The monad-&gt;code approach sounds interesting as way of implementing small DSLs, but it sounds like it wouldn't scale up particular far? If this is true, I'm not sure how well approach would compete with existing scripting languages used in games. I'm not especially excited about using Haskell as a game scripting language. I want to find something to eat into the vast swath of C++ written for games that lua/python/unrealscript/homebrew scripting can't touch. Say, for instance, writing a procedural LOD generator.<BR>
<BR>
Cheers,<BR>
Sam Martin<BR>
<BR>
ps. As a disclaimer - I'm emailing from my work address, but this is all just my own stuff and not necessarily representative of the views of Geomerics! We are definitely not about to ship Haskell-generated C to anyone ;). I'll reply off-list about Geomerics.<BR>
<BR>
<BR>
-----Original Message-----<BR>
From: Ryan Ingram [<A HREF="mailto:ryani.spam@gmail.com">mailto:ryani.spam@gmail.com</A>]<BR>
Sent: 24 April 2009 18:14<BR>
To: Sam Martin<BR>
Cc: haskell-cafe@haskell.org<BR>
Subject: Re: [Haskell-cafe] compilation to C, not via-C<BR>
<BR>
Sam,<BR>
<BR>
I work on graphics engine/pipeline for Spore at Electronic Arts, and<BR>
I've had some similar thoughts as you.&nbsp; But I don't think this is the<BR>
right path for games right now.<BR>
<BR>
The &quot;via C&quot; compiler does generate C code that it puts through GCC.<BR>
There is a post-process step after the code is converted to assembly<BR>
by GCC (see <A HREF="http://hackage.haskell.org/trac/ghc/wiki/Commentary/EvilMangler);">http://hackage.haskell.org/trac/ghc/wiki/Commentary/EvilMangler);</A><BR>
a perl script rewrites the calling convention of all the functions to<BR>
optimize for the code that GHC generates.&nbsp; From what I understand,<BR>
performance is significantly worse without the mangler.&nbsp; So<BR>
interoperability of the generated C-from-Haskell code directly with<BR>
your C code is tricky at best.<BR>
<BR>
However, the generated code is only half the story.&nbsp; The other half is<BR>
that you need the Haskell runtime to go with your program.&nbsp; This<BR>
manages the garbage collector, multithreading-support, etc.&nbsp; As a<BR>
middleware developer, I'm sure you're aware that it would be quite<BR>
difficult to sell &quot;you need this big runtime with unpredictable memory<BR>
requirements&quot; to your potential customers.<BR>
<BR>
That said, don't lose hope.&nbsp; Lots of Haskell development is being done<BR>
for embedded systems, and other things at a similar level as to what<BR>
you want.&nbsp; But what these systems generally do is write a custom monad<BR>
that *outputs* code.&nbsp; You can look at some of the CUFP2008 talks about<BR>
this topic (<A HREF="http://cufp.galois.com/2008/schedule.html);">http://cufp.galois.com/2008/schedule.html);</A> I recommend<BR>
&quot;Controlling Hybrid Vehicles with Haskell&quot;.&nbsp; There was another talk<BR>
about compiling Haskell into Excel spreadsheets for finance, but I<BR>
can't seem to locate it right now.<BR>
<BR>
The basic strategy is to encapsulate all your operations in a monad,<BR>
then write &quot;code generation&quot; that converts the results into C code<BR>
which you can then compile and ship.&nbsp; Unless you're willing to make<BR>
the jump to Haskell as a host language with FFI outcalls to native<BR>
code, I think this is the right strategy right now.<BR>
<BR>
Good luck, and keep us informed how it goes.&nbsp; I expect to hear from<BR>
you at CUFP next year :)<BR>
<BR>
&nbsp;&nbsp; -- ryan<BR>
<BR>
P.S. I saw some demos of Geomerics products; it looks pretty cool.<BR>
What are you guys up to now?<BR>
<BR>
On Fri, Apr 24, 2009 at 9:36 AM, Sam Martin &lt;sam.martin@geomerics.com&gt; wrote:<BR>
&gt; Hi Everyone,<BR>
&gt;<BR>
&gt; It appears the GHC compiler (and other) compile Haskell *via-C* but not<BR>
&gt; *to C*. I've never really understood why there isn't a C generation<BR>
&gt; option, or why GDC ships with its own compulsory copy of gcc.<BR>
&gt;<BR>
&gt; I work in Games middleware, and am very interested in looking at how<BR>
&gt; Haskell could help us. We basically sell C++ libraries. I would like to<BR>
&gt; be able to write some areas of our libraries in Haskell, compile the<BR>
&gt; Haskell to C and incorporate that code into a C++ library.<BR>
&gt;<BR>
&gt; As an example, I think Haskell would be great at doing geometry<BR>
&gt; processing. I don't want to write all our geometry processing code in<BR>
&gt; C++. I'd prefer to write a big chunk of it in Haskell and wrap that in<BR>
&gt; C++.<BR>
&gt;<BR>
&gt; The pattern here is using Haskell to generate C code as the end result.<BR>
&gt; It sounds like this end result isn't that far out of reach, so I'm<BR>
&gt; curious as to why it doesn't appear to be possible at present.<BR>
&gt;<BR>
&gt; Have I missed something? Is there some fundamental reason this isn't<BR>
&gt; possible? Has anyone wished for this before?<BR>
&gt;<BR>
&gt; Any thoughts/help much appreciated,<BR>
&gt;<BR>
&gt; Thanks,<BR>
&gt; Sam Martin<BR>
&gt;<BR>
&gt; ---<BR>
&gt; Lead Programmer<BR>
&gt; www.geomerics.com<BR>
&gt;<BR>
&gt; _______________________________________________<BR>
&gt; Haskell-Cafe mailing list<BR>
&gt; Haskell-Cafe@haskell.org<BR>
&gt; <A HREF="http://www.haskell.org/mailman/listinfo/haskell-cafe">http://www.haskell.org/mailman/listinfo/haskell-cafe</A><BR>
&gt;<BR>
<BR>
</FONT>
</P>

</BODY>
</HTML>