Allow the ability to display all subexpressions of a specific type
I would like to be able to compile a piece of Haskell code using GHC and be able to ask GHC what expressions or sub expressions are of a certain type.
Example: I've run into a fairly nasty bug today. I was using Numeric.Positive in a piece of code. If Positive is instantiated with a number less than or equal to 0, it will throw an exception. I was only explicitly creating the Positive in one spot, where I made sure the number being passed to Positive was constantly equal 100. However, my program was still throwing exceptions, telling me I was trying to create Positive numbers from 0.
After some annoyed grepping and being unable to find any other place I was using Positive, it turned out that I had a piece of code that looked like this:
as :: [Positive] bs :: [Positive] sum as >= sum bs
if either list is empty,
sum will try to create a Positive of value 0.
If I were able to ask GHC where in my code there are subexpressions of type Positive, I would have found this issue a few hours sooner.
I do not know what the best way would be to define a user interface for this. However, even something like a command line option that allows me to specify where Positive is used, and would make GHC spit out line and column numbers (ranges) would be of great help.
I'm sure there is a way to make this useful in ghci, as well.
There is already a ghci command called
:type-at, and this would likely work in similar fashion.
The search should at least be a substring search. For example, searching for Foo will find both FooBar and FooBaz and QuuxFoo.
In a better version, the search should be using some sort of hole type or parameter syntax. For example, Foo _ b b will find Foo Int Float Float as well as Foo Bar () (), but not Foo Baz Int Float.
I don't know how to make the substring search and the parametrised search work together, so those should likely be two separate commands.