<html><head><meta http-equiv="Content-Type" content="text/html; charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">You'll need to run the expression through the whole pipeline.<div class=""><br class=""></div><div class="">1. Parsing</div><div class="">2. Renaming</div><div class="">3. Type-checking</div><div class="">  3a. Constraint generation</div><div class="">  3b. Constraint solving</div><div class="">  3c. Zonking</div><div class="">4. Desugaring</div><div class=""><br class=""></div><div class="">I don't have the exact calls you should use for these steps, but I can give you some pointers.</div><div class=""><br class=""></div><div class="">1. parseExpression</div><div class="">2. rnLExpr</div><div class="">3a. tcInferSigma</div><div class="">3b. simplifyInfer</div><div class="">3c. zonkTopLExpr</div><div class="">4. dsLExpr</div><div class=""><br class=""></div><div class="">You may want to examine tcRnExpr for a template on how to do steps 2 and 3. Note that this function drops the expression and continues only with the type, but the setup around constraint solving is likely what you want.</div><div class=""><br class=""></div><div class="">Another place to look for inspiration is in the pipeline that GHCi uses to process user-written expressions. hscParsedStmt and its caller, hscStmtWithLocation may also be helpful. These functions also compile the statement (which you don't want to do), but you can see where the desugared statement comes out.</div><div class=""><br class=""></div><div class="">I hope this helps move you in the right direction!</div><div class="">Richard<br class=""><div><br class=""><blockquote type="cite" class=""><div class="">On Jan 21, 2020, at 7:21 PM, Yiyun Liu <<a href="mailto:liuyiyun@terpmail.umd.edu" class="">liuyiyun@terpmail.umd.edu</a>> wrote:</div><br class="Apple-interchange-newline"><div class="">
  

    <meta http-equiv="content-type" content="text/html; charset=UTF-8" class="">
  
  <div class=""><p class="">Hi ghc-devs,</p><p class="">I've been trying to implementing a function with the signature:</p><p class="">elaborateExpr :: GhcMonad m => String -> m CoreExpr</p><p class="">It should take a string of the form:</p><p class="">"\x y -> x <> y :: Semigroup a => a -> a -> a"</p><p class="">and give back a core expression with the dictionaries filled in:<br class="">
    </p><p class="">\ ($dSem :: Semigroup a) (x :: a) (y :: a) -> (<>) $dSem
      x y<br class="">
    </p><p class=""><br class="">
    </p><p class="">The goal is to use the function to add elaboration support for
      liquidhaskell.</p><p class="">I looked into the implementation of <a moz-do-not-send="true" href="https://hackage.haskell.org/package/ghc-8.6.5/docs/CoreUtils.html#v:exprType" class="">exprType</a>
      and defined my own <a moz-do-not-send="true" href="https://github.com/yiyunliu/ghc-elaboration-test/blob/30b3307469df15789cf1a323bed96ca42e84aeb5/src/Main.hs#L58" class="">elaborateExpr</a>
      similarly by calling <a moz-do-not-send="true" href="https://hackage.haskell.org/package/ghc-8.6.5/docs/Desugar.html#v:deSugarExpr" class="">desugarExpr</a>
      on the expression (which has type LHsExpr GhcTcId) returned by
      tcInferSigma.</p><p class="">GhcTcId is a synonym of GhcTc so the program I wrote typechecks,
      but it's definitely not right. The elaborateExpr function I
      defined would return something even when the expression doesn't
      typecheck, or occasionally give a runtime exception:</p><p class="">ghc-elaboration-test: panic! (the 'impossible' happened)<br class="">
        (GHC version 8.6.5 for x86_64-unknown-linux):<br class="">
          dsEvBinds</p><p class="">I must have broken some invariants somehow.</p><p class="">What is the correct way of defining such a function (takes a
      string and returns a CoreExpr)? It appears to me that I should
      convert LHsExpr GhcPs into LHsExpr GhcTc first before calling
      deSugarExpr, but I don't know how.</p><p class="">Thank you,</p><p class="">- Yiyun<br class="">
    </p>
  </div>

_______________________________________________<br class="">ghc-devs mailing list<br class=""><a href="mailto:ghc-devs@haskell.org" class="">ghc-devs@haskell.org</a><br class="">http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs<br class=""></div></blockquote></div><br class=""></div></body></html>