A program to show you all the functions you've used in a selected definition

Hi Haskell community!
I was working on a GHC bug and i had to check a lot of functions to figure out what caused the bug, then something came to my mind and I wanted to ask if it would be helpful to implement it.
Imagine you are suspicious that a certain function is causing the trouble you are looking for, but the problem is, that function is made up of 15 other functions and they are all complex and for you to solve the bug, you’d have to take a look at all of them. Would it be helpful if you had a program that you’d give your function to and receive a report of all the functions you’ve used in it (in the default configuration, it would be all the functions down to Prelude.) ?
In a project that you know the codebase of, I don’t think this would improve productivity. But when working with a big project that you are not familiar with, I think this would be really helpful.
What do you think?

I believe debug does something similar (and more, since it prints results for each invocation).

1 Like

Thanks, I didn’t no such thing existed in Haskell!

Although now that I’ve looked at it, even though it has the same functionality, you’d have to edit the source file in order for it to work. On the other hand, I’m thinking about implementing it as a command line program which doesn’t manipulate files.

1 Like

Indeed having to inseret [debug| …] in source files is the most annoying thing in an otherwise stellar library.

Which approach would your tool follow? Would it start from a stack trace? Because unfortunately there are problems there too.

To be honest, I have to research in order to find out what approach is the most efficient and fastest way of building this program. I’m not looking at it as a debugger. The only thing it will do is to pretty-print all the functions used in a selected function, without any analysis or any other debugging feature. The sole purpose of this program would be to give us the building blocks of a function and let us look through it in order to find what we are looking for. I think giving an example would be better way of explaining it: (don’t think about the type or definitions of the functions below)

This is the scenario: your IO output is not printing as many newlines as you want and you now that function printOutput is what actually calls the newline function and it’s what you should investigate.

module Outputable (printOutput) where
.
.
.
f  = map someFunc 
.
.
newline = (++ "\n")
.
.
g = (newline . show) <$> blah
.
.
p = g . f 
.
.
h = uniq . words 
.
.
printOutput = return . h . p 

You give the name of the function you want to this program and it shows you the pretty-printed version of this output:

f  = map someFunc 
newline = (++ "\n")
g = (newline . show) <$> blah
p = g . f 
h = uniq . words 
printOutput = return . h . p 

Now imagine this kind of structure but in a super big codebase. There are many ways to find all the occurrences of newline like grepping it, using xref and …, but the problem is, what if you want to do this for a single function and not all of the source code. It will kind of follow definitions like symlinks and then tell you the function you are looking for is (in our case) g.

I hope I have explain the actual functionality in a way that is clear and understandable.

1 Like

I see, working on the source itself. There are some choices to be made (e.g. show is a function itself, dispatched at compile time); I suspect you can leverage GHC or other tooling to do some of the work for you.

I would such a tool useful: sometimes I am guilty of sprinkling trace and friends everywhere to find the culpirit function.

Good luck!

1 Like

Actually, you are right! I myself was thinking about using GHC as a library to develop it.
I’m super busy right now, both working on GHC (trying to get into more and more) and other stuff. But if you wanted to check it out or help in the progress, it will be on this repository.

In the same vein of producing graph of dependencies, the Provenience package looks interesting: @hackage/provenience

2 Likes

The provenience package is super cool!
Also love the fact that you are sharing it using flora, cool project!