
I've figured out a hack that partially works. If the Name of the
function I'm trying to call is stored in `name`, then the following
code puts its type in `t`:
```
hscenv <- getHscEnv
t <- liftIO $ do
eps <- hscEPS hscenv
let i = fromJust $ lookupNameEnv (eps_PTE eps) name
return varType i
```
This, however, only works if the function has actually been used in
the module before. That makes it more fragile than I'd like.
Also, once I have the type `t`, I'm having trouble creating the
appropriate dictionary to pass as the first argument in core. I can
get the name of the class constraint doing something like:
```
let (ClassPred c _) = classifyPredType . snd . splitAppTy . fst .
splitAppTy $ dropForAlls t
```
But I can't find a function for creating a dictionary (of type Var)
given a Class.
On Fri, Aug 7, 2015 at 3:40 PM, Mike Izbicki
I'm trying to write a GHC plugin. The purpose of the plugin is to provide Haskell bindings to Herbie. Herbie (https://github.com/uwplse/herbie) is a program that takes a mathematical statement as input, and gives you a numerically stable formula to compute it as output. The plugin is supposed to automate this process for Haskell programs.
I can convert the core expressions into a format for Herbie just fine. Where I'm having trouble is converting the output from Herbie back into core. Given a string that represents a numeric operator (e.g. "log" or "+"), I can get that converted into a Name that matches the Name of the version of that operator in scope at the location. But in order to create an Expr, I need to convert the Name into a Var. All the functions that I can find for this (e.g. mkGlobalVar) also require the type of the variable. But I can't find a way to figure out the Type given a Name. How can I do this?