Free dictionary variables in elaborated core expressions

Yiyun Liu liuyiyun at terpmail.umd.edu
Mon Feb 3 02:03:04 UTC 2020


Hi ghc-devs,

About 10 days ago, I made a thread about defining a function called 
elaborateExpr which turns a string into a core expression 
<https://github.com/yiyunliu/ghc-elaboration-test/blob/8f362ad92dc6601b4cb7e4c76f0a42bc6b64480f/src/Main.hs#L55> 
within an interactive context. Now here's an unexpected behavior which 
I'm not sure how to deal with.

Given the expression:

(\x -> x + 1) :: Int -> Int

I expect to get something that looks like:

\ (x :: Int) -> + @ Int GHC.Num.$fNumInt x (GHC.Types.I# 1#)

where GHC.Num.$fNumInt is the exported dictionary.


What I actually get is something like this:

\ (x :: Int) -> + @ Int $dNum_someuniqueid x (GHC.Types.I# 1#)

where $dNum_someuniqueid is a free dictionary variable within the 
expression.


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.

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 getBindings 
<https://hackage.haskell.org/package/ghc-8.6.5/docs/GHC.html#v:getBindings> 
only gives me the expression I elaborated, but the dictionary is no 
where to be found.

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?

Thanks,

- Yiyun

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-devs/attachments/20200202/5aaeda20/attachment.html>


More information about the ghc-devs mailing list