<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: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;}
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:11.0pt;
font-family:"Calibri",sans-serif;}
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;}
p.Code, li.Code, div.Code
{mso-style-name:Code;
mso-style-link:"Code Char";
margin-top:0cm;
margin-right:0cm;
margin-bottom:0cm;
margin-left:36.0pt;
margin-bottom:.0001pt;
font-size:9.0pt;
font-family:"Courier New";}
span.CodeChar
{mso-style-name:"Code Char";
mso-style-link:Code;
font-family:"Courier New";}
span.EmailStyle21
{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;}
@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">
<p class="MsoNormal"><span style="mso-fareast-language:EN-US">That looks plausible to me.<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">The ‘new’ bunch may not actually be new? Maybe they are some of the inputs that are no contradictory, but not yet solved either?<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">What about a flag to say “I made some progress”? Or is that deducible? Is so, good to explain that.<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">Caveat: I’m not a user of plugins! People who are should reply.<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 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>Christiaan Baaij<br>
<b>Sent:</b> 18 July 2018 12:52<br>
<b>To:</b> ghc-devs@haskell.org<br>
<b>Cc:</b> Adam Gundry <adam@well-typed.com><br>
<b>Subject:</b> type-checker plugin API/behaviour change<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<p class="MsoNormal">Hi devs,<o:p></o:p></p>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">Currently, type-checker plugins get to tell the solver its progress using a [TcPluginResult](<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><a href="https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fhackage.haskell.org%2Fpackage%2Fghc-8.4.1%2Fdocs%2FTcRnTypes.html%23t%3ATcPluginResult&data=02%7C01%7Csimonpj%40microsoft.com%7C28d3c329dea345e24ae608d5eca4fd21%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C636675115733740054&sdata=j3EGsCOaHIIN%2FK313dFXdsMz1JUhFqfdCe3nV9qQmCo%3D&reserved=0">http://hackage.haskell.org/package/ghc-8.4.1/docs/TcRnTypes.html#t:TcPluginResult</a>):<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">```<o:p></o:p></p>
</div>
<div>
<div>
<p class="MsoNormal">data TcPluginResult<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"> = TcPluginContradiction [Ct]<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"> -- ^ The plugin found a contradiction.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"> -- The returned constraints are removed from the inert set,<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"> -- and recorded as insoluble.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal"> | TcPluginOk [(EvTerm,Ct)] [Ct]<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"> -- ^ The first field is for constraints that were solved.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"> -- These are removed from the inert set,<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"> -- and the evidence for them is recorded.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"> -- The second field contains new work, that should be processed by<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"> -- the constraint solver.<o:p></o:p></p>
</div>
</div>
<div>
<p class="MsoNormal">```<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">So when asked to solve a _set_ of constraints, a tc plugin basically gets to say:<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">A) This _one_ constraint out of the entire set is wrong, or<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">B) The following _subset_ of constraints is solved (plus some new wanted constraints)<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">Supposedly, picking A leads to better error messages when a constraint is obviously bad (i.e. Int ~ Char). However, the issue is that when a tc plugin picks A, then it will not be called again for the whole set of constraint it originally
got; which in my use-case basically leads to a complete set of (actually solvable) unsolved constraints.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">This is "bad" because it leads to very confusing error messages, when<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">1. Start with a correct program: All constraints solvable => no errors reported<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">2. Add one line of code that doesn't type check<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">3. All constraints unsolvable => errors reported in parts of the program that used to type-check.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">I thought of multiple possible solutions, but changing TcPluginResult to:<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">```<o:p></o:p></p>
</div>
<div>
<div>
<p class="MsoNormal">data TcPluginResult<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"> = TcPluginResult<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"> { contradictions :: [Ct]<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"> -- ^ All of the contradictions the plugin found<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"> , solved :: [(EvTerm,Ct)]<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"> -- ^ Constraints that were solved<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"> , new :: [Ct]<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"> -- ^ New work to be processed by the rest of the constraint solver<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"> }<o:p></o:p></p>
</div>
</div>
<div>
<p class="MsoNormal">```<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">seems the best one as it allows a tc plugin to report _all_ the constraints that are bad, and _all_ the constraints that are bad.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">Thoughts? Perhaps a better solution?<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">Thanks,<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">Christiaan<o:p></o:p></p>
</div>
</div>
</div>
</div>
</body>
</html>