How to turn LHExpr GhcPs into CoreExpr
liuyiyun at terpmail.umd.edu
Tue Jan 21 19:21:38 UTC 2020
I've been trying to implementing a function with the signature:
elaborateExpr :: GhcMonad m => String -> m CoreExpr
It should take a string of the form:
"\x y -> x <> y :: Semigroup a => a -> a -> a"
and give back a core expression with the dictionaries filled in:
\ ($dSem :: Semigroup a) (x :: a) (y :: a) -> (<>) $dSem x y
The goal is to use the function to add elaboration support for
I looked into the implementation of exprType
and defined my own elaborateExpr
similarly by calling desugarExpr
on the expression (which has type LHsExpr GhcTcId) returned by tcInferSigma.
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:
ghc-elaboration-test: panic! (the 'impossible' happened)
(GHC version 8.6.5 for x86_64-unknown-linux):
I must have broken some invariants somehow.
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
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the ghc-devs