<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;}
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;}
span.EmailStyle20
        {mso-style-type:personal-reply;
        font-family:"Calibri",sans-serif;
        color:windowtext;}
span.pl-k
        {mso-style-name:pl-k;}
.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;}
--></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">In your code (elabRnExpr) you have<o:p></o:p></span></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<p class="Code">_ <span class="pl-k"><-</span> perhaps_disable_default_warnings <span class="pl-k">
$</span> simplifyInteractive residual<span style="font-size:11.0pt;font-family:"Calibri",sans-serif;mso-fareast-language:EN-US"><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">You’ll notice that <o:p>
</o:p></span></p>
<p class="Code"><span style="mso-fareast-language:EN-US">simplifyInteractive :: WantedConstraints -> TcM (Bag EvBind)<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">So you are discarding the “evidence bindings” returned by simplifyInteractive.  Those are precisely the bindings of the dictionaries (dictionaries are a form of “evidence”) that you need.  Don’t
 discard them.<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">Untested:<o:p></o:p></span></p>
<p class="Code">ev_binds <span class="pl-k"><-</span> perhaps_disable_default_warnings
<span class="pl-k">$</span> simplifyInteractive residual<o:p></o:p></p>
<p class="Code">let full_expr = mkHsDictLet (EvBinds ev_binds) tc_expr<o:p></o:p></p>
<p class="Code">zonkTopLExpr full_expr<o:p></o:p></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>Yiyun Liu<br>
<b>Sent:</b> 03 February 2020 02:03<br>
<b>To:</b> ghc-devs@haskell.org<br>
<b>Cc:</b> James Parker <jp@jamesparker.me><br>
<b>Subject:</b> Free dictionary variables in elaborated core expressions<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<p>Hi ghc-devs,<o:p></o:p></p>
<p>About 10 days ago, I made a thread about defining a function called elaborateExpr which
<a href="https://github.com/yiyunliu/ghc-elaboration-test/blob/8f362ad92dc6601b4cb7e4c76f0a42bc6b64480f/src/Main.hs#L55">
turns a string into a core expression</a> within an interactive context. Now here's an unexpected behavior which I'm not sure how to deal with.<o:p></o:p></p>
<p>Given the expression: <o:p></o:p></p>
<p>(\x -> x + 1) :: Int -> Int<o:p></o:p></p>
<p>I expect to get something that looks like:<o:p></o:p></p>
<p>\ (x :: Int) -> + @ Int GHC.Num.$fNumInt x (GHC.Types.I# 1#)<o:p></o:p></p>
<p>where GHC.Num.$fNumInt is the exported dictionary.<o:p></o:p></p>
<p><o:p> </o:p></p>
<p>What I actually get is something like this:<o:p></o:p></p>
<p>\ (x :: Int) -> + @ Int $dNum_someuniqueid x (GHC.Types.I# 1#)<o:p></o:p></p>
<p>where $dNum_someuniqueid is a free dictionary variable within the expression.<o:p></o:p></p>
<p><o:p> </o:p></p>
<p>I was confused by the occurrence of the free variable $dNum at first, but after running the command: "ghc -ddump-ds-preopt somefile.hs" to dump the core bindings, I found that the dictionary variables like $dNum_ are actually local variables defined at the
 top-level.<o:p></o:p></p>
<p>My objective is to inline those top-level dictionary definitions into the core expression using let bindings, but it seems tricky since I'm doing everything within an interactive context.  Calling
<a href="https://hackage.haskell.org/package/ghc-8.6.5/docs/GHC.html#v:getBindings">
getBindings</a> only gives me the expression I elaborated, but the dictionary is no where to be found.<o:p></o:p></p>
<p>Interestingly, when I turn on flags such as "DeferTypedHoles" or "DeferOutOfScopeVariables", all the dictionaries are defined locally in let bindings. However, I can't replicate that behavior even with the flags on in the interactive context. How do I find
 the dictionaries?<o:p></o:p></p>
<p>Thanks,<o:p></o:p></p>
<p>- Yiyun<o:p></o:p></p>
</div>
</div>
</body>
</html>