<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=utf-8">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@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;}
/* 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.Code, li.Code, div.Code
{mso-style-name:Code;
margin-top:0cm;
margin-right:0cm;
margin-bottom:0cm;
margin-left:36.0pt;
margin-bottom:.0001pt;
font-size:9.0pt;
font-family:"Courier New";}
p.msonormal0, li.msonormal0, div.msonormal0
{mso-style-name:msonormal;
mso-margin-top-alt:auto;
margin-right:0cm;
mso-margin-bottom-alt:auto;
margin-left:0cm;
font-size:12.0pt;
font-family:"Times New Roman",serif;}
p.m-525007982728833755msolistparagraph, li.m-525007982728833755msolistparagraph, div.m-525007982728833755msolistparagraph
{mso-style-name:m_-525007982728833755msolistparagraph;
mso-margin-top-alt:auto;
margin-right:0cm;
mso-margin-bottom-alt:auto;
margin-left:0cm;
font-size:12.0pt;
font-family:"Times New Roman",serif;}
p.m-525007982728833755code, li.m-525007982728833755code, div.m-525007982728833755code
{mso-style-name:m_-525007982728833755code;
mso-margin-top-alt:auto;
margin-right:0cm;
mso-margin-bottom-alt:auto;
margin-left:0cm;
font-size:12.0pt;
font-family:"Times New Roman",serif;}
span.EmailStyle21
{mso-style-type:personal-reply;
font-family:"Calibri",sans-serif;
color:windowtext;
font-weight:normal;
font-style:normal;
text-decoration:none none;}
.MsoChpDefault
{mso-style-type:export-only;
font-family:"Calibri",sans-serif;
mso-fareast-language:EN-US;}
.MsoPapDefault
{mso-style-type:export-only;
margin-top:6.0pt;
margin-right:0cm;
margin-bottom:6.0pt;
margin-left:0cm;}
@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:516119309;
mso-list-template-ids:-2074417530;}
@list l1
{mso-list-id:812647172;
mso-list-template-ids:-1249713672;}
@list l1:level1
{mso-level-start-at:2;
mso-level-tab-stop:36.0pt;
mso-level-number-position:left;
text-indent:-18.0pt;}
@list l2
{mso-list-id:1332876747;
mso-list-template-ids:1786551420;}
@list l2:level1
{mso-level-start-at:4;
mso-level-tab-stop:36.0pt;
mso-level-number-position:left;
text-indent:-18.0pt;}
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="mso-margin-top-alt:6.0pt;margin-right:0cm;margin-bottom:6.0pt;margin-left:36.0pt">
<span style="font-size:9.0pt;font-family:"Arial",sans-serif">I have been under the impression that we don't even want to print those.</span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-family:"Calibri",sans-serif">On the contrary, inside GHC I /do/ want to print them. Otherwise how can I see what the renamer has done?<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Calibri",sans-serif"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Calibri",sans-serif">Simon<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Calibri",sans-serif"><o:p> </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 #E1E1E1 1.0pt;padding:3.0pt 0cm 0cm 0cm">
<p class="MsoNormal"><b><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri",sans-serif">From:</span></b><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri",sans-serif"> Shayan Najd [mailto:sh.najd@gmail.com]
<br>
<b>Sent:</b> 28 July 2017 12:20<br>
<b>To:</b> Simon Peyton Jones <simonpj@microsoft.com><br>
<b>Cc:</b> ghc-devs@haskell.org; Alan & Kim Zimmerman <alan.zimm@gmail.com><br>
<b>Subject:</b> Re: Operating on HsSyn<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:6.0pt;margin-right:0cm;margin-bottom:6.0pt;margin-left:0cm">
<span style="font-family:"Arial",sans-serif">Before all this, we may need to discuss a bit about the intended semantics of<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:6.0pt;margin-right:0cm;margin-bottom:6.0pt;margin-left:0cm">
<span style="font-family:"Arial",sans-serif">`Outputable`: does it need to print `PostRn`, or `PostTc` fields; or `Out`<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:6.0pt;margin-right:0cm;margin-bottom:6.0pt;margin-left:0cm">
<span style="font-family:"Arial",sans-serif">suffixed constructors? If not, then we only need to write a set of instances<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:6.0pt;margin-right:0cm;margin-bottom:6.0pt;margin-left:0cm">
<span style="font-family:"Arial",sans-serif">for the base growable AST, once and for all. Such instances will be polymorphic<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:6.0pt;margin-right:0cm;margin-bottom:6.0pt;margin-left:0cm">
<span style="font-family:"Arial",sans-serif">on the extension descriptor `p`, and do not need to mention the constraints like<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:6.0pt;margin-right:0cm;margin-bottom:6.0pt;margin-left:0cm">
<span style="font-family:"Arial",sans-serif">`(PostRn p (IdP p)`, since these are just extensions and not part of the base<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:6.0pt;margin-right:0cm;margin-bottom:6.0pt;margin-left:0cm">
<span style="font-family:"Arial",sans-serif">growable AST. Or, am I missing something about the intended semantics of<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:6.0pt;margin-right:0cm;margin-bottom:6.0pt;margin-left:0cm">
<span style="font-family:"Arial",sans-serif">`Outputable`?<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:6.0pt;margin-right:0cm;margin-bottom:6.0pt;margin-left:0cm">
<span style="font-size:9.0pt;font-family:"Arial",sans-serif"><o:p> </o:p></span></p>
</div>
</div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:6.0pt;margin-right:0cm;margin-bottom:6.0pt;margin-left:0cm">
<span style="font-family:"Arial",sans-serif">You write</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:6.0pt;margin-right:0cm;margin-bottom:6.0pt;margin-left:0cm">
<o:p> </o:p></p>
</div>
<div>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0cm 0cm 0cm 6.0pt;margin-left:4.8pt;margin-right:0cm">
<p class="MsoNormal" style="mso-margin-top-alt:6.0pt;margin-right:0cm;margin-bottom:6.0pt;margin-left:0cm">
So today we never print these annotations, to avoid bloating the instance contexts, which can be painful. <o:p></o:p></p>
</blockquote>
</div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:6.0pt;margin-right:0cm;margin-bottom:6.0pt;margin-left:0cm">
<o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:6.0pt;margin-right:0cm;margin-bottom:6.0pt;margin-left:0cm">
<span style="font-size:9.0pt;font-family:"Arial",sans-serif">I have been under the impression that we don't even want to print those.</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:6.0pt;margin-right:0cm;margin-bottom:6.0pt;margin-left:0cm">
<o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:6.0pt;margin-right:0cm;margin-bottom:6.0pt;margin-left:0cm">
<span style="font-size:9.0pt;font-family:"Arial",sans-serif">Of course, there are scenarios (like `Show` instances) where we do want to write </span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:6.0pt;margin-right:0cm;margin-bottom:6.0pt;margin-left:0cm">
<span style="font-size:9.0pt;font-family:"Arial",sans-serif">compositional / generic functions that take into account the extensions.</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:6.0pt;margin-right:0cm;margin-bottom:6.0pt;margin-left:0cm">
<span style="font-size:9.0pt;font-family:"Arial",sans-serif">Here is my abstract overview of the scenario, that may help the discussion.</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:6.0pt;margin-right:0cm;margin-bottom:6.0pt;margin-left:0cm">
<span style="font-size:9.0pt;font-family:"Arial",sans-serif">Consider data types `A`, `B`, and `C` (say, one AST datatype per compiler phase) that</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:6.0pt;margin-right:0cm;margin-bottom:6.0pt;margin-left:0cm">
<span style="font-size:9.0pt;font-family:"Arial",sans-serif"> are defined as extensions to a base datatype `T`:</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:6.0pt;margin-right:0cm;margin-bottom:6.0pt;margin-left:0cm">
<o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:6.0pt;margin-right:0cm;margin-bottom:6.0pt;margin-left:0cm">
<span style="font-size:9.0pt;font-family:"Courier New"">> A = T XA</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:6.0pt;margin-right:0cm;margin-bottom:6.0pt;margin-left:0cm">
<span style="font-size:9.0pt;font-family:"Courier New"">> B = T XB</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:6.0pt;margin-right:0cm;margin-bottom:6.0pt;margin-left:0cm">
<span style="font-size:9.0pt;font-family:"Courier New"">> C = T XC</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:6.0pt;margin-right:0cm;margin-bottom:6.0pt;margin-left:0cm">
<o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:6.0pt;margin-right:0cm;margin-bottom:6.0pt;margin-left:0cm">
<span style="font-size:9.0pt;font-family:"Arial",sans-serif">where `</span><span style="font-size:9.0pt;font-family:"Courier New"">X*</span><span style="font-size:9.0pt;font-family:"Arial",sans-serif">`s are extension descriptors.</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:6.0pt;margin-right:0cm;margin-bottom:6.0pt;margin-left:0cm">
<span style="font-size:9.0pt;font-family:"Arial",sans-serif">Now, say we want to a define functions `</span><span style="font-size:9.0pt;font-family:"Courier New"">f_A</span><span style="font-size:9.0pt;font-family:"Arial",sans-serif">`, `</span><span style="font-size:9.0pt;font-family:"Courier New"">f_B</span><span style="font-size:9.0pt;font-family:"Arial",sans-serif">`,
and `</span><span style="font-size:9.0pt;font-family:"Courier New"">f_C</span><span style="font-size:9.0pt;font-family:"Arial",sans-serif">` over `</span><span style="font-size:9.0pt;font-family:"Courier New"">A</span><span style="font-size:9.0pt;font-family:"Arial",sans-serif">`,
`</span><span style="font-size:9.0pt;font-family:"Courier New"">B</span><span style="font-size:9.0pt;font-family:"Arial",sans-serif">`, and `</span><span style="font-size:9.0pt;font-family:"Courier New"">C</span><span style="font-size:9.0pt;font-family:"Arial",sans-serif">`.</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:6.0pt;margin-right:0cm;margin-bottom:6.0pt;margin-left:0cm">
<span style="font-size:9.0pt;font-family:"Arial",sans-serif">We have two main alternatives: </span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:6.0pt;margin-right:0cm;margin-bottom:6.0pt;margin-left:0cm">
<span style="font-size:9.0pt;font-family:"Arial",sans-serif">(a) either we write these (manually or using the deriving mechanism) separately</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:6.0pt;margin-right:0cm;margin-bottom:6.0pt;margin-left:0cm">
<span style="font-size:9.0pt;font-family:"Arial",sans-serif">(b) or we write a generic / parametric function `</span><span style="font-size:9.0pt;font-family:"Courier New"">g</span><span style="font-size:9.0pt;font-family:"Arial",sans-serif">` over `</span><span style="font-size:9.0pt;font-family:"Courier New"">T</span><span style="font-size:9.0pt;font-family:"Arial",sans-serif">`,
and reuse that to define `</span><span style="font-size:9.0pt;font-family:"Courier New"">f_*</span><span style="font-size:9.0pt;font-family:"Arial",sans-serif">`s</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:6.0pt;margin-right:0cm;margin-bottom:6.0pt;margin-left:0cm">
<o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:6.0pt;margin-right:0cm;margin-bottom:6.0pt;margin-left:0cm">
<span style="font-size:9.0pt;font-family:"Arial",sans-serif">Of course, (b) is preferable in theory , but not always possible or preferable in practice.</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:6.0pt;margin-right:0cm;margin-bottom:6.0pt;margin-left:0cm">
<span style="font-size:9.0pt;font-family:"Arial",sans-serif">In which case, we can always resort to (a).</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:6.0pt;margin-right:0cm;margin-bottom:6.0pt;margin-left:0cm">
<span style="font-size:9.0pt;font-family:"Arial",sans-serif">The more varying are the definitions of `f_A`, `f_B`, and `f_C` the more parametric should </span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:6.0pt;margin-right:0cm;margin-bottom:6.0pt;margin-left:0cm">
<span style="font-size:9.0pt;font-family:"Arial",sans-serif">`g` get, as this is the case for any generic function.</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:6.0pt;margin-right:0cm;margin-bottom:6.0pt;margin-left:0cm">
<o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:6.0pt;margin-right:0cm;margin-bottom:6.0pt;margin-left:0cm">
<span style="font-size:9.0pt;font-family:"Arial",sans-serif">With a correct design, I believe, these are all independent of Trees that Grow story itself: </span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:6.0pt;margin-right:0cm;margin-bottom:6.0pt;margin-left:0cm">
<span style="font-size:9.0pt;font-family:"Arial",sans-serif">we are now not only trying to reuse data types, and functions agnostic towards extensions</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:6.0pt;margin-right:0cm;margin-bottom:6.0pt;margin-left:0cm">
<span style="font-size:9.0pt;font-family:"Arial",sans-serif">(pretty printers in my view of their semantics), but also reuse functions with parametric / </span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:6.0pt;margin-right:0cm;margin-bottom:6.0pt;margin-left:0cm">
<span style="font-size:9.0pt;font-family:"Arial",sans-serif">varying behaviour with respect to extensions. </span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:6.0pt;margin-right:0cm;margin-bottom:6.0pt;margin-left:0cm">
<o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:6.0pt;margin-right:0cm;margin-bottom:6.0pt;margin-left:0cm">
/Shayan<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:6.0pt;margin-right:0cm;margin-bottom:6.0pt;margin-left:0cm">
<o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:6.0pt;margin-right:0cm;margin-bottom:6.0pt;margin-left:0cm">
<o:p> </o:p></p>
</div>
</div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:6.0pt;margin-right:0cm;margin-bottom:6.0pt;margin-left:0cm">
<o:p> </o:p></p>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:6.0pt;margin-right:0cm;margin-bottom:6.0pt;margin-left:0cm">
On Fri, Jul 28, 2017 at 10:18 AM, Simon Peyton Jones <<a href="mailto:simonpj@microsoft.com" target="_blank">simonpj@microsoft.com</a>> wrote:<o:p></o:p></p>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0cm 0cm 0cm 6.0pt;margin-left:4.8pt;margin-right:0cm">
<div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-family:"Calibri",sans-serif">Devs,</span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-family:"Calibri",sans-serif"> </span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-family:"Calibri",sans-serif">Shayan is working away on “Trees that grow”… do keep it on your radar:</span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-family:"Calibri",sans-serif"> </span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;margin-bottom:12.0pt;margin-left:36.0pt">
<b><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri",sans-serif">To:</span></b><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri",sans-serif"> ghc-devs
<br>
<b>Sent:</b> 25 May 2017 23:49</span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;margin-left:36.0pt">
<span style="font-size:11.0pt;font-family:"Calibri",sans-serif">Do take a look at this:</span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;margin-left:36.0pt">
<span style="font-size:11.0pt;font-family:"Calibri",sans-serif"> </span><o:p></o:p></p>
<p class="m-525007982728833755msolistparagraph" style="margin-left:72.0pt"><span style="font-size:11.0pt;font-family:Symbol">·</span><span style="font-size:7.0pt">
</span><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">We propose to re-engineer HsSyn itself. This will touch a
<b>lot</b> of code.</span><o:p></o:p></p>
<p class="m-525007982728833755msolistparagraph" style="margin-left:72.0pt"><span style="font-size:11.0pt;font-family:Symbol">·</span><span style="font-size:7.0pt">
</span><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">But it’s very neat, and will bring big long-term advantages</span><o:p></o:p></p>
<p class="m-525007982728833755msolistparagraph" style="margin-left:72.0pt"><span style="font-size:11.0pt;font-family:Symbol">·</span><span style="font-size:7.0pt">
</span><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">And we can do it a bit at a time</span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;margin-left:36.0pt">
<span style="font-size:11.0pt;font-family:"Calibri",sans-serif"> </span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;margin-left:36.0pt">
<span style="font-size:11.0pt;font-family:"Calibri",sans-serif">The wiki page </span>
<a href="https://ghc.haskell.org/trac/ghc/wiki/ImplementingTreesThatGrow" target="_blank">https://ghc.haskell.org/trac/ghc/wiki/ImplementingTreesThatGrow</a>
<span style="font-size:11.0pt;font-family:"Calibri",sans-serif">has the details.</span>
<a name="m_-525007982728833755__MailEndCompose">I</a><span style="mso-bookmark:m_-525007982728833755__MailEndCompose"></span><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">t’s entirely an internal change, not a change to GHC’s specification,
so it’s independent of the GHC proposals process. But I’d value the opinion of other GHC devs</span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-family:"Calibri",sans-serif"> </span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-family:"Calibri",sans-serif">Meanwhile I have a question. When pretty-printing HsSyn we often have a situation like this:</span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-family:"Calibri",sans-serif"> </span><o:p></o:p></p>
<p class="m-525007982728833755code"> data Pass = Parsed | Renamed | Typechecked<o:p></o:p></p>
<p class="m-525007982728833755code"> <o:p></o:p></p>
<p class="m-525007982728833755code"> data HsExpr (p :: Pass) = HsVar (IdP p) | ....<o:p></o:p></p>
<p class="m-525007982728833755code"> <o:p></o:p></p>
<p class="m-525007982728833755code"> type famliy IdP p where<o:p></o:p></p>
<p class="m-525007982728833755code"> IdP Parsed = RdrName<o:p></o:p></p>
<p class="m-525007982728833755code"> IdP Renamed = Name<o:p></o:p></p>
<p class="m-525007982728833755code"> IdP Typechecked = Id<o:p></o:p></p>
<p class="m-525007982728833755code"> <o:p></o:p></p>
<p class="m-525007982728833755code"> instance (Outputable (IdP p)) => Outputable (HsExpr p) where<o:p></o:p></p>
<p class="m-525007982728833755code"> ppr (HsVar v) = ppr v<o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-family:"Calibri",sans-serif"> </span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-family:"Calibri",sans-serif">The (ppr v) requires (Outputable (IdP p)), hence the context.</span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-family:"Calibri",sans-serif"> </span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-family:"Calibri",sans-serif">Moreover, and more seriously, there are things we just can't pretty-print</span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-family:"Calibri",sans-serif">right now. For example, HsExpr has this data constructor:</span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-family:"Calibri",sans-serif"> </span><o:p></o:p></p>
<p class="m-525007982728833755code"> data HsExpr p = ...<o:p></o:p></p>
<p class="m-525007982728833755code"> | OpApp (LHsExpr p)<o:p></o:p></p>
<p class="m-525007982728833755code"> (LHsExpr p)<o:p></o:p></p>
<p class="m-525007982728833755code"> (PostRn p Fixity)<o:p></o:p></p>
<p class="m-525007982728833755code"> (LHsExpr p)<o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-family:"Calibri",sans-serif"> </span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-family:"Calibri",sans-serif">To pretty-print the third argument, we'd need to add</span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-family:"Calibri",sans-serif"> </span><o:p></o:p></p>
<p class="m-525007982728833755code"> instance (Outputable (IdP p),<o:p></o:p></p>
<p class="m-525007982728833755code"> Outputable (PostRn p Fixity)) -- New<o:p></o:p></p>
<p class="m-525007982728833755code"> => Outputable (HsExpr p) where<o:p></o:p></p>
<p class="m-525007982728833755code"> ppr (HsVar v) = ppr v<o:p></o:p></p>
<p class="m-525007982728833755code"> <o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-family:"Calibri",sans-serif">and that gets onerous.
<i>So today we never print these annotations</i>, to avoid bloating the instance contexts, which can be painful. It bit me yesterday.</span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-family:"Calibri",sans-serif"> </span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-family:"Calibri",sans-serif">We have bitten that bullet for the Data class: look at HsExtension.DataId, which abbreviates the long list of dictionaries:</span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-family:"Calibri",sans-serif"> </span><o:p></o:p></p>
<p class="m-525007982728833755code"> type DataId p =<o:p></o:p></p>
<p class="m-525007982728833755code"> ( Data p<o:p></o:p></p>
<p class="m-525007982728833755code"> , ForallX Data p<o:p></o:p></p>
<p class="m-525007982728833755code"> , Data (NameOrRdrName (IdP p))<o:p></o:p></p>
<p class="m-525007982728833755code"> , Data (IdP p)<o:p></o:p></p>
<p class="m-525007982728833755code"> , Data (PostRn p (IdP p))<o:p></o:p></p>
<p class="m-525007982728833755code"> , Data (PostRn p (Located Name))<o:p></o:p></p>
<p class="m-525007982728833755code"> , Data (PostRn p Bool)<o:p></o:p></p>
<p class="m-525007982728833755code"> , Data (PostRn p Fixity)<o:p></o:p></p>
<p class="m-525007982728833755code"> ,..and nine more... )<o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-family:"Calibri",sans-serif"> </span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-family:"Calibri",sans-serif">Let me note in passing that [<a href="https://ghc.haskell.org/trac/ghc/wiki/QuantifiedContexts" target="_blank">wiki:QuantifiedContexts</a>]
would make this somewhat shorter</span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-family:"Calibri",sans-serif"> </span><o:p></o:p></p>
<p class="m-525007982728833755code"> type DataId p =<o:p></o:p></p>
<p class="m-525007982728833755code"> ( Data p<o:p></o:p></p>
<p class="m-525007982728833755code"> , ForallX Data p<o:p></o:p></p>
<p class="m-525007982728833755code"> , Data (NameOrRdrName (IdP p))<o:p></o:p></p>
<p class="m-525007982728833755code"> , Data (IdP p)<o:p></o:p></p>
<p class="m-525007982728833755code"> , forall t. Data t => Data (PostRn p t))<o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-family:"Calibri",sans-serif"> </span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-family:"Calibri",sans-serif">But we still need one item in this list for each type function,</span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-family:"Calibri",sans-serif">and I am worried about how this scales to the</span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-family:"Calibri",sans-serif">[<a href="https://ghc.haskell.org/trac/ghc/wiki/ImplementingTreesThatGrow" target="_blank">wiki:ImplementingTreesThatGrow</a>] story,
when we have a type</span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-family:"Calibri",sans-serif">function for each data constructor -- and there are a
<b>lot</b> of data</span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-family:"Calibri",sans-serif">constructors.</span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-family:"Calibri",sans-serif"> </span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><b><span style="font-family:"Calibri",sans-serif">So I have four questions</span></b><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-family:"Calibri",sans-serif"> </span><o:p></o:p></p>
<ol start="1" type="1">
<li class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;margin-left:0cm;mso-list:l0 level1 lfo1">
<span style="font-family:"Calibri",sans-serif">I think we should probably use a superclass instead of a type synonym</span><o:p></o:p></li></ol>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-family:"Calibri",sans-serif"> </span><o:p></o:p></p>
<p class="m-525007982728833755code">class (Data p, ForallX Data p, ....) => DataId p where {}<o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-family:"Calibri",sans-serif"> </span><o:p></o:p></p>
<p class="m-525007982728833755msolistparagraph"><span style="font-family:"Calibri",sans-serif">Why? Only one argument to pass, and to pass on to successive calls. I see no downside.</span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-family:"Calibri",sans-serif"> </span><o:p></o:p></p>
<ol start="2" type="1">
<li class="MsoNormal" style="mso-margin-top-alt:auto;margin-bottom:12.0pt;margin-left:0cm;mso-list:l1 level1 lfo2">
<span style="font-family:"Calibri",sans-serif">Shall we treat Outputable like Data? (I.e. make an abbreviation for a long list of Outputable instances and use it everywhere)</span><o:p></o:p></li><li class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;margin-left:0cm;mso-list:l1 level1 lfo2">
<span style="font-family:"Calibri",sans-serif">I thought of another way to do it (pass a token); see below</span><o:p></o:p></li></ol>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-family:"Calibri",sans-serif"> </span><o:p></o:p></p>
<ol start="4" type="1">
<li class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;margin-left:0cm;mso-list:l2 level1 lfo3">
<span style="font-family:"Calibri",sans-serif">Are there any other ways?</span><o:p></o:p></li></ol>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-family:"Calibri",sans-serif"> </span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-family:"Calibri",sans-serif"> </span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><b><span style="font-family:"Calibri",sans-serif">Token passing idea.</span></b><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-family:"Calibri",sans-serif"> </span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-family:"Calibri",sans-serif">Perhaps instead of passing lots of functions, we pass a singleton token</span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-family:"Calibri",sans-serif">that encodes the pass, like this:</span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-family:"Calibri",sans-serif"> </span><o:p></o:p></p>
<p class="m-525007982728833755code"> instance (PassC p) => Outputable (HsExpr p) where<o:p></o:p></p>
<p class="m-525007982728833755code"> ppr (HsVar v) = case getPass :: IsPass p of<o:p></o:p></p>
<p class="m-525007982728833755code"> IsParsed -> ppr v<o:p></o:p></p>
<p class="m-525007982728833755code"> IsRenamed -> ppr v<o:p></o:p></p>
<p class="m-525007982728833755code"> IsTypechecked -> ppr v<o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-family:"Calibri",sans-serif"> </span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-family:"Calibri",sans-serif">The three ppr's are at different types, of course; that's the point.</span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-family:"Calibri",sans-serif">The infrastructure is something like</span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-family:"Calibri",sans-serif"> </span><o:p></o:p></p>
<p class="m-525007982728833755code"> class PassC p where<o:p></o:p></p>
<p class="m-525007982728833755code"> getPass :: IsPass p<o:p></o:p></p>
<p class="m-525007982728833755code"> <o:p></o:p></p>
<p class="m-525007982728833755code"> data IsPass p where<o:p></o:p></p>
<p class="m-525007982728833755code"> IsParsed :: IsPass Parsed<o:p></o:p></p>
<p class="m-525007982728833755code"> IsRenamed :: IsParsed Renamed<o:p></o:p></p>
<p class="m-525007982728833755code"> IsTypechecked :: IsParsed Typechecked<o:p></o:p></p>
<p class="m-525007982728833755code"> <o:p></o:p></p>
<p class="m-525007982728833755code"> instance PassC Parsed where getPass = IsParsed<o:p></o:p></p>
<p class="m-525007982728833755code"> ...etc...<o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-family:"Calibri",sans-serif"> </span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-family:"Calibri",sans-serif">Now we could sweep away all those OutputableX classes,</span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-family:"Calibri",sans-serif">replacing them with dynamic tests on the singletons IsParsed etc.</span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-family:"Calibri",sans-serif">This would have advantages:</span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-family:"Calibri",sans-serif"> </span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-family:"Calibri",sans-serif">- Probably faster: there's a dynamic test, but many fewer dictionary</span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-family:"Calibri",sans-serif"> arguments and higher-order function dispatch</span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-family:"Calibri",sans-serif"> </span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-family:"Calibri",sans-serif">- Only one dictionary to pass; programming is easier.</span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-family:"Calibri",sans-serif"> </span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-family:"Calibri",sans-serif">The big downside is that it's not extensible: it works only because</span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-family:"Calibri",sans-serif">we know the three cases. But the "Trees that Grow" story really doesn't</span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-family:"Calibri",sans-serif">scale well to pretty-printing: so maybe we should just give up on that?</span><o:p></o:p></p>
</div>
</div>
</blockquote>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
</div>
</div>
</body>
</html>