<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta name="Generator" content="Microsoft Word 12 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:Wingdings;
        panose-1:5 0 0 0 0 0 0 0 0 0;}
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
@font-face
        {font-family:Verdana;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
p.MsoListParagraph, li.MsoListParagraph, div.MsoListParagraph
        {mso-style-priority:34;
        margin-top:0cm;
        margin-right:0cm;
        margin-bottom:0cm;
        margin-left:36.0pt;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";}
span.EmailStyle17
        {mso-style-type:personal-reply;
        font-family:"Verdana","sans-serif";
        color:#1F497D;}
span.apple-converted-space
        {mso-style-name:apple-converted-space;}
.MsoChpDefault
        {mso-style-type:export-only;}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
        {page:WordSection1;}
/* List Definitions */
@list l0
        {mso-list-id:809787669;
        mso-list-type:hybrid;
        mso-list-template-ids:1178094236 134807553 134807555 134807557 134807553 134807555 134807557 134807553 134807555 134807557;}
@list l0:level1
        {mso-level-number-format:bullet;
        mso-level-text:\F0B7;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;
        font-family:Symbol;}
@list l1
        {mso-list-id:1250696558;
        mso-list-type:hybrid;
        mso-list-template-ids:-1053914936 134807553 134807555 134807557 134807553 134807555 134807557 134807553 134807555 134807557;}
@list l1:level1
        {mso-level-number-format:bullet;
        mso-level-text:\F0B7;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        margin-left:40.8pt;
        text-indent:-18.0pt;
        font-family:Symbol;}
@list l1:level2
        {mso-level-number-format:bullet;
        mso-level-text:o;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        margin-left:76.8pt;
        text-indent:-18.0pt;
        font-family:"Courier New";}
ol
        {margin-bottom:0cm;}
ul
        {margin-bottom:0cm;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-GB" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal" style="margin-left:36.0pt">I would like to explore making a backend for .NET. I've done a lot of background reading about previous .NET and JVM attempts for Haskell. It seems like several folks have made significant progress in the past
 and, with the exception of UHC, I can't find any code around the internet from the previous efforts. I realize that in total it's a huge undertaking and codegen is only one of several significant hurdles to success.<o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Verdana&quot;,&quot;sans-serif&quot;;color:#1F497D"><o:p>&nbsp;</o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Verdana&quot;,&quot;sans-serif&quot;;color:#1F497D">Someone should start a wiki page about this!&nbsp; It comes up regularly.&nbsp; (That doesn&#8217;t mean it&#8217;s a bad idea; just that we should share wisdom on it.)&nbsp; Maybe there
 is one, in which case perhaps it could be updated?<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Verdana&quot;,&quot;sans-serif&quot;;color:#1F497D"><o:p>&nbsp;</o:p></span></p>
<p class="MsoNormal" style="mso-margin-top-alt:6.0pt;margin-right:0cm;margin-bottom:6.0pt;margin-left:0cm">
<span style="font-size:11.0pt;font-family:&quot;Verdana&quot;,&quot;sans-serif&quot;;color:#1F497D">Some thoughts (which, if someone would like to transfer these to the wiki page, perhaps in more coherent form):<o:p></o:p></span></p>
<p class="MsoListParagraph" style="mso-margin-top-alt:6.0pt;margin-right:0cm;margin-bottom:6.0pt;margin-left:36.0pt;text-indent:-18.0pt;mso-list:l0 level1 lfo1">
<![if !supportLists]><span style="font-size:11.0pt;font-family:Symbol;color:#1F497D"><span style="mso-list:Ignore">&middot;<span style="font:7.0pt &quot;Times New Roman&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</span></span></span><![endif]><span style="font-size:11.0pt;font-family:&quot;Verdana&quot;,&quot;sans-serif&quot;;color:#1F497D">Check out Frege.&nbsp; Maybe others.&nbsp; I think several folk are working on .NET or JVM projects.<o:p></o:p></span></p>
<p class="MsoListParagraph" style="mso-margin-top-alt:6.0pt;margin-right:0cm;margin-bottom:6.0pt;margin-left:36.0pt;text-indent:-18.0pt;mso-list:l0 level1 lfo1">
<![if !supportLists]><span style="font-size:11.0pt;font-family:Symbol;color:#1F497D"><span style="mso-list:Ignore">&middot;<span style="font:7.0pt &quot;Times New Roman&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</span></span></span><![endif]><span style="font-size:11.0pt;font-family:&quot;Verdana&quot;,&quot;sans-serif&quot;;color:#1F497D">Do you want to inter-operate with .NET, or compile to .NET bytecode.&nbsp; These are very different?&nbsp; I&#8217;ll assume the latter.<o:p></o:p></span></p>
<p class="MsoListParagraph" style="mso-margin-top-alt:6.0pt;margin-right:0cm;margin-bottom:6.0pt;margin-left:36.0pt;text-indent:-18.0pt;mso-list:l0 level1 lfo1">
<![if !supportLists]><span style="font-size:11.0pt;font-family:Symbol;color:#1F497D"><span style="mso-list:Ignore">&middot;<span style="font:7.0pt &quot;Times New Roman&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</span></span></span><![endif]><span style="font-size:11.0pt;font-family:&quot;Verdana&quot;,&quot;sans-serif&quot;;color:#1F497D">Do you want to compile to verifiable .NET bytecode?&nbsp; This is hard.&nbsp; GHC&#8217;s type system is more expressive than .NET&#8217;s in many ways (higher kinded type
 variables, kind polymorphism...).&nbsp; And less expressive in others (sub-typing). Compiling to verifiable bytecode would require lots of run-time type-tests (which we know will succeed) to reassure .NET that it&#8217;s all kosher.&nbsp; Figuring out how to minimise these
 tests would be a challenge in itself.<o:p></o:p></span></p>
<p class="MsoListParagraph" style="mso-margin-top-alt:6.0pt;margin-right:0cm;margin-bottom:6.0pt;margin-left:36.0pt;text-indent:-18.0pt;mso-list:l0 level1 lfo1">
<![if !supportLists]><span style="font-size:11.0pt;font-family:Symbol;color:#1F497D"><span style="mso-list:Ignore">&middot;<span style="font:7.0pt &quot;Times New Roman&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</span></span></span><![endif]><span style="font-size:11.0pt;font-family:&quot;Verdana&quot;,&quot;sans-serif&quot;;color:#1F497D">And of course this affects whether you can go via C#, since that requires the program to be well typed in the .NET sense.<o:p></o:p></span></p>
<p class="MsoListParagraph" style="mso-margin-top-alt:6.0pt;margin-right:0cm;margin-bottom:6.0pt;margin-left:36.0pt;text-indent:-18.0pt;mso-list:l0 level1 lfo1">
<![if !supportLists]><span style="font-size:11.0pt;font-family:Symbol;color:#1F497D"><span style="mso-list:Ignore">&middot;<span style="font:7.0pt &quot;Times New Roman&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</span></span></span><![endif]><span style="font-size:11.0pt;font-family:&quot;Verdana&quot;,&quot;sans-serif&quot;;color:#1F497D">Do you want simply to
<b>run</b> <b>Haskell programs</b> on .NET or do you want <b>Haskell programs to call .NET libraries</b>? &nbsp;I assume the latter.&nbsp; But that means that .NET types must be manifested somehow as Haskell types.&nbsp;&nbsp; A big issue is how much of .NET&#8217;s type system you
 want to suck into Haskell.&nbsp; A stressful example: can you define in Haskell a type that sub-classes an imported .NET type.<o:p></o:p></span></p>
<p class="MsoListParagraph" style="mso-margin-top-alt:6.0pt;margin-right:0cm;margin-bottom:6.0pt;margin-left:36.0pt">
<span style="font-size:11.0pt;font-family:&quot;Verdana&quot;,&quot;sans-serif&quot;;color:#1F497D">Daan and Mark and Sigbjorn and I wrote papers about this stuff</span><span style="font-size:10.0pt;font-family:&quot;Verdana&quot;,&quot;sans-serif&quot;;color:#1F497D">.</span><span style="font-size:11.0pt;font-family:&quot;Verdana&quot;,&quot;sans-serif&quot;">&nbsp;</span><span style="font-size:11.0pt;font-family:&quot;Verdana&quot;,&quot;sans-serif&quot;;color:#1F497D">Look
 at the papers under &quot;Foreign language integration&quot; on</span><span class="apple-converted-space"><span style="font-size:11.0pt;font-family:&quot;Verdana&quot;,&quot;sans-serif&quot;">&nbsp;</span></span><span style="font-size:11.0pt;font-family:&quot;Verdana&quot;,&quot;sans-serif&quot;"><a href="http://research.microsoft.com/en-us/um/people/simonpj/papers/papers.html"><span style="color:purple">http://research.microsoft.com/en-us/um/people/simonpj/papers/papers.html</span></a>.
 &nbsp;Oh, and this:<span class="apple-converted-space">&nbsp;</span><a href="http://research.microsoft.com/en-us/um/people/simonpj/papers/oo-haskell/index.htm"><span style="color:purple">http://research.microsoft.com/en-us/um/people/simonpj/papers/oo-haskell/index.htm</span></a><o:p></o:p></span></p>
<p class="MsoListParagraph" style="mso-margin-top-alt:6.0pt;margin-right:0cm;margin-bottom:6.0pt;margin-left:40.8pt;text-indent:-18.0pt;mso-list:l1 level1 lfo2">
<![if !supportLists]><span style="font-size:10.0pt;font-family:Symbol;color:#1F497D"><span style="mso-list:Ignore">&middot;<span style="font:7.0pt &quot;Times New Roman&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</span></span></span><![endif]><span style="font-size:11.0pt;font-family:&quot;Verdana&quot;,&quot;sans-serif&quot;">I&#8217;d be inclined to start from Core rather than STG, perhaps the output of CorePrep.&nbsp; STG is a bit encrusted (though we&#8217;re about to simplify it a bit).&nbsp; But honestly
 they are pretty similar.</span><span style="font-size:10.0pt;font-family:&quot;Verdana&quot;,&quot;sans-serif&quot;;color:#1F497D"><o:p></o:p></span></p>
<p class="MsoListParagraph" style="mso-margin-top-alt:6.0pt;margin-right:0cm;margin-bottom:6.0pt;margin-left:40.8pt">
<span style="font-size:11.0pt;font-family:&quot;Verdana&quot;,&quot;sans-serif&quot;">Cmm would be a bad choice. It&#8217;s far too low level.<o:p></o:p></span></p>
<p class="MsoListParagraph" style="mso-margin-top-alt:6.0pt;margin-right:0cm;margin-bottom:6.0pt;margin-left:40.8pt;text-indent:-18.0pt;mso-list:l1 level1 lfo2">
<![if !supportLists]><span style="font-size:11.0pt;font-family:Symbol"><span style="mso-list:Ignore">&middot;<span style="font:7.0pt &quot;Times New Roman&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</span></span></span><![endif]><span style="font-size:11.0pt;font-family:&quot;Verdana&quot;,&quot;sans-serif&quot;">Another major issues is that of primops (prelude/primops.txt.pp).&nbsp; Things like add Int# or Float# are fine, but what about forking a thread, or throwing an exception?&nbsp;
<o:p></o:p></span></p>
<p class="MsoListParagraph" style="mso-margin-top-alt:6.0pt;margin-right:0cm;margin-bottom:6.0pt;margin-left:76.8pt;text-indent:-18.0pt;mso-list:l1 level2 lfo2">
<![if !supportLists]><span style="font-size:11.0pt;font-family:&quot;Courier New&quot;"><span style="mso-list:Ignore">o<span style="font:7.0pt &quot;Times New Roman&quot;">&nbsp;&nbsp;
</span></span></span><![endif]><span style="font-size:11.0pt;font-family:&quot;Verdana&quot;,&quot;sans-serif&quot;">One possibility is to try to emulate them all.&nbsp; I have no idea how hard that would be, but GHC&#8217;s I/O libraries rely heavily on lightweight concurrency.<o:p></o:p></span></p>
<p class="MsoListParagraph" style="mso-margin-top-alt:6.0pt;margin-right:0cm;margin-bottom:6.0pt;margin-left:76.8pt;text-indent:-18.0pt;mso-list:l1 level2 lfo2">
<![if !supportLists]><span style="font-size:11.0pt;font-family:&quot;Courier New&quot;"><span style="mso-list:Ignore">o<span style="font:7.0pt &quot;Times New Roman&quot;">&nbsp;&nbsp;
</span></span></span><![endif]><span style="font-size:11.0pt;font-family:&quot;Verdana&quot;,&quot;sans-serif&quot;">Another is to trim the list of PrimOps, and only support some of them.&nbsp; That&#8217;s easier, but you&#8217;d have to dump a lot of the &#8216;base&#8217; package (particularly I/O) and
 re-implement it using the .NET libraries instead.<o:p></o:p></span></p>
<p class="MsoListParagraph" style="mso-margin-top-alt:6.0pt;margin-right:0cm;margin-bottom:6.0pt;margin-left:40.8pt">
<span style="font-size:10.0pt;font-family:&quot;Verdana&quot;,&quot;sans-serif&quot;;color:#1F497D"><o:p>&nbsp;</o:p></span></p>
<p class="MsoListParagraph" style="mso-margin-top-alt:6.0pt;margin-right:0cm;margin-bottom:6.0pt;margin-left:0cm">
<span style="font-size:10.0pt;font-family:&quot;Verdana&quot;,&quot;sans-serif&quot;;color:#1F497D">I hope this is of at least some use<o:p></o:p></span></p>
<p class="MsoListParagraph" style="mso-margin-top-alt:6.0pt;margin-right:0cm;margin-bottom:6.0pt;margin-left:0cm">
<span style="font-size:10.0pt;font-family:&quot;Verdana&quot;,&quot;sans-serif&quot;;color:#1F497D">Simon<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Verdana&quot;,&quot;sans-serif&quot;;color:#1F497D"><o:p>&nbsp;</o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Verdana&quot;,&quot;sans-serif&quot;;color:#1F497D"><o:p>&nbsp;</o:p></span></p>
<div style="border:none;border-left:solid blue 1.5pt;padding:0cm 0cm 0cm 4.0pt">
<div>
<div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0cm 0cm 0cm">
<p class="MsoNormal"><b><span lang="EN-US" style="font-size:10.0pt;font-family:&quot;Tahoma&quot;,&quot;sans-serif&quot;">From:</span></b><span lang="EN-US" style="font-size:10.0pt;font-family:&quot;Tahoma&quot;,&quot;sans-serif&quot;"> glasgow-haskell-users-bounces@haskell.org [mailto:glasgow-haskell-users-bounces@haskell.org]
<b>On Behalf Of </b>Jason Dagit<br>
<b>Sent:</b> 28 January 2013 01:16<br>
<b>To:</b> glasgow-haskell-users@haskell.org<br>
<b>Subject:</b> How to get started with a new backend?<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
<div>
<p class="MsoNormal">I would like to explore making a backend for .NET. I've done a lot of background reading about previous .NET and JVM attempts for Haskell. It seems like several folks have made significant progress in the past and, with the exception of
 UHC, I can't find any code around the internet from the previous efforts. I realize that in total it's a huge undertaking and codegen is only one of several significant hurdles to success.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
</div>
<div>
<div>
<p class="MsoNormal">I would like to get a very, very, very simple translation working inside GHC. If all I can compile and run is fibonacci, then I would be quite happy. For my first attempt, proof of concept is sufficient.<o:p></o:p></p>
</div>
</div>
<div>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
</div>
<p class="MsoNormal">I found a lot of good documentation on the ghc trac for how the compilation phases work and what happens in the different parts of the backend. The documentation is excellent, especially compared to other compilers I've looked at.<o:p></o:p></p>
<div>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
</div>
<div>
<p class="MsoNormal">When I started looking at how to write the code, I started to wonder about the &quot;least effort&quot; path to getting something (anything?) working. Here are some questions:<o:p></o:p></p>
<div>
<p class="MsoNormal">&nbsp; * Haskell.NET seems to be dead. Does anyone know where their code went?<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">&nbsp; * Did lambdavm also disappear? (JVM I know, but close enough to be useful)<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">&nbsp; * Would it make sense to copy&amp;modify the -fvia-C backend to generate C#? The trac claims that ghc can compile itself to C so that only standard gnu C tools are needed to build an unregistered compiler. Could I use this trick to translate
 programs to C#?<o:p></o:p></p>
</div>
</div>
<div>
<p class="MsoNormal">&nbsp; * What stage in the pipeline should I translate from? Core? STG? Cmm?<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">&nbsp; * Which directories/source files should I look at to get familiar with the code gen? I've heard the LLVM codegen is relatively simple.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">&nbsp; * Any other advice?<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
</div>
<div>
<p class="MsoNormal">Thank you in advance!<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">Jason<o:p></o:p></p>
</div>
</div>
</div>
</body>
</html>