<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;}
@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;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri",sans-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;}
pre
        {mso-style-priority:99;
        mso-style-link:"HTML Preformatted Char";
        margin:0cm;
        margin-bottom:.0001pt;
        font-size:10.0pt;
        font-family:"Courier New";}
p.Code, li.Code, div.Code
        {mso-style-name:Code;
        margin-top:0cm;
        margin-right:0cm;
        margin-bottom:0cm;
        margin-left:22.7pt;
        margin-bottom:.0001pt;
        font-size:10.0pt;
        font-family:"Courier New";
        font-weight:bold;}
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: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;
        mso-fareast-language:EN-GB;}
span.gmail-line
        {mso-style-name:gmail-line;}
span.gmail-cm
        {mso-style-name:gmail-cm;}
span.EmailStyle23
        {mso-style-type:personal-reply;
        font-family:"Calibri",sans-serif;
        color:windowtext;}
.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;}
--></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">
<pre style="margin-left:36.0pt"><span style="font-family:"Arial",sans-serif">I'm wondering about the claim "and that can float out of the implication". The Note does go on to mention #15009 --- and I understand how that Wanted floats *with* #15009 --- but as written, it sounds like the Wanted could float even without #15009.<o:p></o:p></span></pre>
<pre style="margin-left:36.0pt"><span style="font-family:"Arial",sans-serif"><o:p> </o:p></span></pre>
<pre><span style="font-family:"Arial",sans-serif">Consider our example<o:p></o:p></span></pre>
<pre><span class="gmail-cm">     forall a[2]. b[1] ~ a[2] => beta[1] ~ a[2]<o:p></o:p></span></pre>
<pre><span class="gmail-cm"><o:p> </o:p></span></pre>
<pre><span style="font-family:"Arial",sans-serif">If we leave the Given oriented as it is, the (beta~a) constraint cannot float, because it mentions a, which is bound by the forall<o:p></o:p></span></pre>
<pre><span style="font-family:"Arial",sans-serif"><o:p> </o:p></span></pre>
<pre><span style="font-family:"Arial",sans-serif">If we swizzle the Given we get this:<o:p></o:p></span></pre>
<pre><span class="gmail-cm">     forall a[2]. a[2] ~ b[1] => beta[1] ~ a[2]<o:p></o:p></span></pre>
<pre><span style="font-family:"Arial",sans-serif"><o:p> </o:p></span></pre>
<pre><span style="font-family:"Arial",sans-serif">Now we’ll use that Given to rewrite the Wanted, to get this:<o:p></o:p></span></pre>
<pre><span class="gmail-cm">     forall a[2]. a[2] ~ b[1] => beta[1] ~ b[1]<o:p></o:p></span></pre>
<pre><span style="font-family:"Arial",sans-serif"><o:p> </o:p></span></pre>
<pre><span style="font-family:"Arial",sans-serif">Now the Wanted can float – it no longer mentions a.<o:p></o:p></span></pre>
<pre><span style="font-family:"Arial",sans-serif"><o:p> </o:p></span></pre>
<pre><span style="font-family:"Arial",sans-serif">But wait!  There’s a second thing that prevents floating: we never float out of an implication that binds Given equalities.   But not quite: the Note [Let-bound skolems] explains that we don’t treat as “binding a Given equality” an equality whose LHS is one of the skolems bound by this very implication.  And lo!  in the implication<o:p></o:p></span></pre>
<pre><span class="gmail-cm">     forall a[2]. a[2] ~ b[1] => beta[1] ~ b[1]<o:p></o:p></span></pre>
<pre><span style="font-family:"Arial",sans-serif"><o:p> </o:p></span></pre>
<pre><span style="font-family:"Arial",sans-serif">the a[2] on the LHS is indeed bound by this implication.  So we do not disable floating (despite the apparent Given equality), and can float to give<o:p></o:p></span></pre>
<pre><span class="gmail-cm">     beta[1] ~ b[1],  (forall a[2]. a[2] ~ b[1] => <empty>)<o:p></o:p></span></pre>
<pre><span style="font-family:"Arial",sans-serif"><o:p> </o:p></span></pre>
<pre><span style="font-family:"Arial",sans-serif">Does that help explain? If so, might you update the Note(s) so they are clearer?<o:p></o:p></span></pre>
<pre><span style="font-family:"Arial",sans-serif"><o:p> </o:p></span></pre>
<pre><span style="font-family:"Arial",sans-serif">Thanks<o:p></o:p></span></pre>
<pre><span style="font-family:"Arial",sans-serif"><o:p> </o:p></span></pre>
<pre><span style="font-family:"Arial",sans-serif">Simon<o:p></o:p></span></pre>
<pre><span class="gmail-cm"><o:p> </o:p></span></pre>
<pre><o:p> </o:p></pre>
<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">rom:</span></b><span lang="EN-US"> Nicolas Frisby <nicolas.frisby@gmail.com>
<br>
<b>Sent:</b> 16 May 2019 06:03<br>
<b>To:</b> ghc-devs@haskell.org<br>
<b>Cc:</b> Richard Eisenberg <rae@cs.brynmawr.edu>; Simon Peyton Jones <simonpj@microsoft.com><br>
<b>Subject:</b> clarification re Note [Deeper level on the left]<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><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">
<a href="https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgitlab.haskell.org%2Fghc%2Fghc%2Fblob%2Fmaster%2Fcompiler%2Ftypecheck%2FTcUnify.hs%23L1754&data=02%7C01%7Csimonpj%40microsoft.com%7Cfd5cf759668242dc797f08d6d9bbddb8%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C636935798235607415&sdata=cRksGeyxgGtNkWOf7nuF42BruMVyK8JyqbbAZC02DJM%3D&reserved=0">https://gitlab.haskell.org/ghc/ghc/blob/master/compiler/typecheck/TcUnify.hs#L1754</a>
 contains<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>
<pre><span class="gmail-cm">```<o:p></o:p></span></pre>
<pre><span class="gmail-cm">Note [Deeper level on the left]</span><o:p></o:p></pre>
<pre><span class="gmail-cm">~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~</span><o:p></o:p></pre>
<pre><span class="gmail-cm">The most important thing is that we want to put tyvars with</span><o:p></o:p></pre>
<pre><span class="gmail-cm">the deepest level on the left.  The reason to do so differs for</span><o:p></o:p></pre>
<pre><span class="gmail-cm">Wanteds and Givens, but either way, deepest wins!  Simple.</span><o:p></o:p></pre>
<pre><o:p> </o:p></pre>
<pre><span class="gmail-cm">* Wanteds.  Putting the deepest variable on the left maximise the</span><o:p></o:p></pre>
<pre><span class="gmail-cm">  chances that it's a touchable meta-tyvar which can be solved.</span><o:p></o:p></pre>
<pre><o:p> </o:p></pre>
<pre><span class="gmail-cm">* Givens. Suppose we have something like</span><o:p></o:p></pre>
<pre><span class="gmail-cm">     forall a[2]. b[1] ~ a[2] => beta[1] ~ a[2]</span><o:p></o:p></pre>
<pre><o:p> </o:p></pre>
<pre><span class="gmail-cm">  If we orient the Given a[2] on the left, we'll rewrite the Wanted to</span><o:p></o:p></pre>
<pre><span class="gmail-cm">  (beta[1] ~ b[1]), and that can float out of the implication.</span><o:p></o:p></pre>
<pre><span class="gmail-cm">  Otherwise it can't.  By putting the deepest variable on the left</span><o:p></o:p></pre>
<pre><span class="gmail-cm">  we maximise our changes of eliminating skolem capture.<o:p></o:p></span></pre>
<pre><span class="gmail-cm"><o:p> </o:p></span></pre>
<pre><span class="gmail-cm">  See also TcSMonad Note [Let-bound skolems] for another reason<o:p></o:p></span></pre>
<pre><span class="gmail-cm">  to orient with the deepest skolem on the left.<o:p></o:p></span></pre>
<pre><span class="gmail-cm">  IMPORTANT NOTE: this test does a level-number comparison on</span><o:p></o:p></pre>
<pre><span class="gmail-cm">  skolems, so it's important that skolems have (accurate) level</span><o:p></o:p></pre>
<pre><span class="gmail-cm">  numbers.</span><o:p></o:p></pre>
<pre><o:p> </o:p></pre>
<pre><span class="gmail-cm">See #15009 for an further analysis of why "deepest on the left"</span><o:p></o:p></pre>
<pre><span class="gmail-cm">is a good plan.<o:p></o:p></span></pre>
<pre>```<o:p></o:p></pre>
<pre><o:p> </o:p></pre>
<div>
<pre><span style="font-family:"Arial",sans-serif">I'm wondering about the claim "and that can float out of the implication". The Note does go on to mention #15009 --- and I understand how that Wanted floats *with* #15009 --- but as written, it sounds like the Wanted could float even without #15009.<o:p></o:p></span></pre>
</div>
<div>
<pre><span style="font-family:"Arial",sans-serif"><o:p> </o:p></span></pre>
</div>
<div>
<pre><span style="font-family:"Arial",sans-serif">Am I missing something? Roughly: I'm asking because I need to decide if there's a reason for my typechecker plugin to bother with "eliminating skolem capture" when #15009 does *not* apply.<br><br>Thanks. -Nick<o:p></o:p></span></pre>
</div>
</div>
</div>
</div>
</div>
</body>
</html>