<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<p>Thanks for having the patience to read through my code! That's
exactly what I was missing. I did print out the return value in my
debug code at some point, but the prettyprinter only shows the
suffix of the dictionary variable without the rhs so I totally
missed it.</p>
<p>Also, I noticed that simplifyInteractive actually returns an
empty bag in the (\x -> x + 1) example I gave, and I actually
ended up using the EvBinds returned by simplifyInfer to add the
let binding:</p>
<p><b> (_, _, evbs, residual, _) <- simplifyInfer tclvl</b><b><br>
</b><b> infer_mode</b><b><br>
</b><b> []</b><b><br>
</b><b> [(fresh_it,
res_ty)]</b><b><br>
</b><b> lie</b><b><br>
</b><b> evbs' <- perhaps_disable_default_warnings $
simplifyInteractive residual</b></p>
<p><b> let full_expr = </b><b><b>(mkHsDictLet (EvBinds evbs')
(mkHsDictLet evbs tc_expr))</b></b></p>
<p><b> zonkTopLExpr full_expr<br>
</b></p>
<p><b></b><br>
</p>
<p>- Yiyun<br>
</p>
<p><br>
</p>
<p><br>
</p>
<div class="moz-cite-prefix">On 2/3/20 4:18 AM, Simon Peyton Jones
wrote:<br>
</div>
<blockquote type="cite"
cite="mid:AM5PR8303MB0082F5EBC2A9A450F232A5B6AD000@AM5PR8303MB0082.EURPRD83.prod.outlook.com">
<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]-->
<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
<a class="moz-txt-link-rfc2396E" href="mailto:ghc-devs-bounces@haskell.org"><ghc-devs-bounces@haskell.org></a>
<b>On Behalf Of </b>Yiyun Liu<br>
<b>Sent:</b> 03 February 2020 02:03<br>
<b>To:</b> <a class="moz-txt-link-abbreviated" href="mailto:ghc-devs@haskell.org">ghc-devs@haskell.org</a><br>
<b>Cc:</b> James Parker <a class="moz-txt-link-rfc2396E" href="mailto:jp@jamesparker.me"><jp@jamesparker.me></a><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"
moz-do-not-send="true">
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"
moz-do-not-send="true">
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>
</blockquote>
</body>
</html>