<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 15 (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:Consolas;
panose-1:2 11 6 9 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0cm;
font-size:11.0pt;
font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
pre
{mso-style-priority:99;
mso-style-link:"HTML Preformatted Char";
margin:0cm;
font-size:10.0pt;
font-family:"Courier New";}
p.MsoListParagraph, li.MsoListParagraph, div.MsoListParagraph
{mso-style-priority:34;
margin-top:0cm;
margin-right:0cm;
margin-bottom:0cm;
margin-left:36.0pt;
font-size:11.0pt;
font-family:"Calibri",sans-serif;}
span.HTMLPreformattedChar
{mso-style-name:"HTML Preformatted Char";
mso-style-priority:99;
mso-style-link:"HTML Preformatted";
font-family:Consolas;}
span.EmailStyle22
{mso-style-type:personal-reply;
font-family:"Calibri",sans-serif;
color:windowtext;}
.MsoChpDefault
{mso-style-type:export-only;
font-size:10.0pt;}
@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:500240040;
mso-list-template-ids:37639014;}
@list l0:level1
{mso-level-number-format:bullet;
mso-level-text:\F0B7;
mso-level-tab-stop:36.0pt;
mso-level-number-position:left;
text-indent:-18.0pt;
mso-ansi-font-size:10.0pt;
font-family:Symbol;}
@list l0:level2
{mso-level-number-format:bullet;
mso-level-text:o;
mso-level-tab-stop:72.0pt;
mso-level-number-position:left;
text-indent:-18.0pt;
mso-ansi-font-size:10.0pt;
font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";}
@list l0:level3
{mso-level-number-format:bullet;
mso-level-text:\F0A7;
mso-level-tab-stop:108.0pt;
mso-level-number-position:left;
text-indent:-18.0pt;
mso-ansi-font-size:10.0pt;
font-family:Wingdings;}
@list l0:level4
{mso-level-number-format:bullet;
mso-level-text:\F0A7;
mso-level-tab-stop:144.0pt;
mso-level-number-position:left;
text-indent:-18.0pt;
mso-ansi-font-size:10.0pt;
font-family:Wingdings;}
@list l0:level5
{mso-level-number-format:bullet;
mso-level-text:\F0A7;
mso-level-tab-stop:180.0pt;
mso-level-number-position:left;
text-indent:-18.0pt;
mso-ansi-font-size:10.0pt;
font-family:Wingdings;}
@list l0:level6
{mso-level-number-format:bullet;
mso-level-text:\F0A7;
mso-level-tab-stop:216.0pt;
mso-level-number-position:left;
text-indent:-18.0pt;
mso-ansi-font-size:10.0pt;
font-family:Wingdings;}
@list l0:level7
{mso-level-number-format:bullet;
mso-level-text:\F0A7;
mso-level-tab-stop:252.0pt;
mso-level-number-position:left;
text-indent:-18.0pt;
mso-ansi-font-size:10.0pt;
font-family:Wingdings;}
@list l0:level8
{mso-level-number-format:bullet;
mso-level-text:\F0A7;
mso-level-tab-stop:288.0pt;
mso-level-number-position:left;
text-indent:-18.0pt;
mso-ansi-font-size:10.0pt;
font-family:Wingdings;}
@list l0:level9
{mso-level-number-format:bullet;
mso-level-text:\F0A7;
mso-level-tab-stop:324.0pt;
mso-level-number-position:left;
text-indent:-18.0pt;
mso-ansi-font-size:10.0pt;
font-family:Wingdings;}
@list l1
{mso-list-id:709652552;
mso-list-type:hybrid;
mso-list-template-ids:-2058442910 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;
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;
text-indent:-18.0pt;
font-family:"Courier New";}
@list l1:level3
{mso-level-number-format:bullet;
mso-level-text:\F0A7;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-18.0pt;
font-family:Wingdings;}
@list l1:level4
{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:level5
{mso-level-number-format:bullet;
mso-level-text:o;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-18.0pt;
font-family:"Courier New";}
@list l1:level6
{mso-level-number-format:bullet;
mso-level-text:\F0A7;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-18.0pt;
font-family:Wingdings;}
@list l1:level7
{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:level8
{mso-level-number-format:bullet;
mso-level-text:o;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-18.0pt;
font-family:"Courier New";}
@list l1:level9
{mso-level-number-format:bullet;
mso-level-text:\F0A7;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-18.0pt;
font-family:Wingdings;}
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" style="word-wrap:break-word">
<div class="WordSection1">
<p style="margin-left:36.0pt">Is there anywhere on the GHC wiki that explains how to interpret this output, and says that the type and dictionary applications ARE there, just not shown by '-ddump-tc'?<o:p></o:p></p>
<p style="margin-left:36.0pt">Perhaps it would be helpful to add some basic description of what comes out of the typechecker to a page like this one? (below)<o:p></o:p></p>
<p style="margin-left:36.0pt"> <a href="https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgitlab.haskell.org%2Fghc%2Fghc%2F-%2Fwikis%2Fcommentary%2Fcompiler%2Fhsc-main&data=04%7C01%7Csimonpj%40microsoft.com%7Cab59b17d2f394945ad1e08d9a2b96c81%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637719740212483767%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=WZL1VADZPUlaOACd58K1XZO5MzPOKrfLFMSuBD%2FGW44%3D&reserved=0">
https://gitlab.haskell.org/ghc/ghc/-/wikis/commentary/compiler/hsc-main</a><o:p></o:p></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US">Yes it would! Would you care to start such a wiki page (a new one; don’t just clutter up the one you point to)? You can write down what you know. Don’t worry if you aren’t 100% sure – we can
correct it. And if you outright don’t know, leave a “What should I say here?” note.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<p style="margin-left:36.0pt">"This late desugaring is somewhat unusual. It is much more common to desugar the program before typechecking, or renaming, because that presents the renamer and typechecker with a much smaller language to deal with. However, GHC's
organisation means that<o:p></o:p></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US">This note is now slightly out of date. We are now, very carefully, doing some desugaring
<b>before</b> typechecking. See<o:p></o:p></span></p>
<ul style="margin-top:0cm" type="disc">
<li class="MsoListParagraph" style="margin-left:0cm;mso-list:l1 level1 lfo2"><span style="mso-fareast-language:EN-US">Note [Handling overloaded and rebindable constructs] in GHC.Rename.Expr<o:p></o:p></span></li><li class="MsoListParagraph" style="margin-left:0cm;mso-list:l1 level1 lfo2"><span style="mso-fareast-language:EN-US">Note [Rebindable syntax and HsExpansion] in GHC.Hs.Expr<o:p></o:p></span></li></ul>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US">You can and should point to these and similar Notes from the wiki page you write. Indeed there may be some part of what you write that would be better framed as Note in GHC’s source code.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US">Thanks!<o:p></o:p></span></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US">Simon<o:p></o:p></span></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<div>
<p class="MsoNormal"><span style="font-size:8.0pt">PS: I am leaving Microsoft at the end of November 2021, at which point
<a href="mailto:simonpj@microsoft.com"><span style="color:#0563C1">simonpj@microsoft.com</span></a> will cease to work. Use
<a href="mailto:simon.peytonjones@gmail.com"><span style="color:#0563C1">simon.peytonjones@gmail.com</span></a> instead. (For now, it just forwards to simonpj@microsoft.com.)<o:p></o:p></span></p>
</div>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US"><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">From:</span></b><span lang="EN-US"> ghc-devs <ghc-devs-bounces@haskell.org>
<b>On Behalf Of </b>Benjamin Redelings<br>
<b>Sent:</b> 08 November 2021 13:12<br>
<b>To:</b> Richard Eisenberg <lists@richarde.dev><br>
<b>Cc:</b> ghc-devs@haskell.org<br>
<b>Subject:</b> Re: Output language of typechecking pass?<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<p>Hi,<o:p></o:p></p>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<pre><o:p> </o:p></pre>
<pre>Questions:<o:p></o:p></pre>
<pre><o:p> </o:p></pre>
<pre>1. It seems like this separation is actually necessary, in order to apply generalization only to let arguments written by the programmer, and not to let bindings introduced during desugaring. Is that right?<o:p></o:p></pre>
</blockquote>
<pre><o:p> </o:p></pre>
<pre>I don't think so. That is, if we did it all in one pass, I still think we could get generalization right.<o:p></o:p></pre>
</blockquote>
<p>I guess I asked this question wrong. I mean to say, if we did the two passes in the reverse order (desugaring first, followed by typechecking), that would not work, right?<o:p></o:p></p>
<p>As the wiki says:<o:p></o:p></p>
<p>"This late desugaring is somewhat unusual. It is much more common to desugar the program before typechecking, or renaming, because that presents the renamer and typechecker with a much smaller language to deal with. However, GHC's organisation means that<o:p></o:p></p>
<ul type="disc">
<li class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;mso-list:l0 level1 lfo1">
error messages can display precisely the syntax that the user wrote; and<o:p></o:p></li><li class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;mso-list:l0 level1 lfo1">
desugaring is not required to preserve type-inference properties.<o:p></o:p></li></ul>
<p>"<o:p></o:p></p>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<pre><o:p> </o:p></pre>
<pre>2. Does the output of type checking contain type lambdas?<o:p></o:p></pre>
</blockquote>
<pre><o:p> </o:p></pre>
<pre>Yes. See below.<o:p></o:p></pre>
<pre><o:p> </o:p></pre>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<pre><o:p> </o:p></pre>
<pre>3. Does the type checking pass determine where to add dictionary arguments?<o:p></o:p></pre>
</blockquote>
<pre><o:p> </o:p></pre>
<pre>Yes. See below.<o:p></o:p></pre>
<pre><o:p> </o:p></pre>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<pre><o:p> </o:p></pre>
<pre>4. Are there any other resources I should be looking at?<o:p></o:p></pre>
</blockquote>
<pre><o:p> </o:p></pre>
<pre>Yes. You want to enable -fprint-typechecker-elaboration (and possible -fprint-explicit-coercions). With the former, you get to see all this stuff you're looking for. It's normally suppressed so that the output resembles the user's code.<o:p></o:p></pre>
<pre><o:p> </o:p></pre>
<pre>I hope this helps!<o:p></o:p></pre>
<pre>Richard<o:p></o:p></pre>
</blockquote>
<p>Hmm... so, I think I see how this works now. I don't think '-fprint-explicit-coercions' does anything here though.<o:p></o:p></p>
<p>$ ghc -ddump-tc Test2.hs -fprint-typechecker-elaboration<o:p></o:p></p>
<p>...<o:p></o:p></p>
<p>AbsBinds [a_a2hp] [$dNum_a2hB]<br>
{Exports: [g <= g_a2hz<br>
wrap: <>]<br>
Exported types: g :: forall a. Num a => a -> a -> a<br>
[LclId]<br>
Binds: g x_aYk y_aYl = (y_aYl * x_aYk) + 1<br>
Evidence: [EvBinds{[W] $dNum_a2hs = $dNum_a2hq<br>
[W] $dNum_a2hw = $dNum_a2hq<br>
[W] $dNum_a2hq = $dNum_a2hB}]}<o:p></o:p></p>
<p>...<o:p></o:p></p>
<p>The type and dictionary arguments are visible here (along with the evidence bindings), but type and dictionary applications are only visible if you use -ddump-tc-ast, which is a lot more verbose. (I don't think there is another flag that shows these applications?)
Since I didn't initially know what "evidence" was, and there is nothing to say that a_a2hp is a type lambda argument, this was pretty opaque until I managed to read the tc-ast and the light went on.<o:p></o:p></p>
<p>I can see now that the type and dictionary arguments are added by annotating the AST.<o:p></o:p></p>
<p>Is there anywhere on the GHC wiki that explains how to interpret this output, and says that the type and dictionary applications ARE there, just not shown by '-ddump-tc'?<o:p></o:p></p>
<p>Perhaps it would be helpful to add some basic description of what comes out of the typechecker to a page like this one? (below)<o:p></o:p></p>
<p> <a href="https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgitlab.haskell.org%2Fghc%2Fghc%2F-%2Fwikis%2Fcommentary%2Fcompiler%2Fhsc-main&data=04%7C01%7Csimonpj%40microsoft.com%7Cab59b17d2f394945ad1e08d9a2b96c81%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637719740212483767%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=WZL1VADZPUlaOACd58K1XZO5MzPOKrfLFMSuBD%2FGW44%3D&reserved=0">
https://gitlab.haskell.org/ghc/ghc/-/wikis/commentary/compiler/hsc-main</a><o:p></o:p></p>
<p>-BenRI<o:p></o:p></p>
<p><o:p> </o:p></p>
</div>
</div>
</body>
</html>