Way to get all "unbound ids" in a Core expression
I was attempting to (essentially) do dependency analysis on a Core expression. So I'd like to get all the unbound names in an expression, e.g. for
\a::Bool -> False
I would like to get Bool
and False
, but not a
.
This looks a lot like what the functions in CoreFVs
are supposed to do. However, there is a major difference: they do not include type constructors. This behaviour ultimately stems from tyCoFVsOfType
, which ignores the head of a TyConApp
.
It was pointed out to me on IRC that this may just be the right sense of "free variable" for GHC, in that type constructors cannot be substituted for, so aren't variables in the same way.
However any implementation of an "unbound ids" function is going to share 90% of its code with expr_vars
, so I wonder whether it would be better for that to include type constructors and to filter them out where they're not desirable (as many of the clients already do for global ids). However, this would require changing tyCoFVsOfType
which seems very scary.
I'd also appreciate it if anyone knows of any better way of doing this!