Is there a way to set a breakpoint at a multiline function defined in a let block in ghci?

Viewed 71

Using ghci, if I have something like

1 g x y = 
2     let -- ...
3     in -- ... (recursively calls itself) 
3 
4 
5 f x = -- ... (calls g once)

I can set a breakpoint at g using :break g, call f, and have the program break every time g gets called.

However, I'm not using g anywhere else, so I would like to write

1 f x =
2     let g x' y =
3         let -- ...
4         in -- ...
5     in -- ...

Is there a way to break every time g gets called? I noticed that if g is one line, I can just say :break 2.

I can also break at the let statement for g, using :break 3; but, I would like to bind the arguments g gets called with, and I don't think that lets me do that.

1 Answers

In GHC 9.0.1 a feature has been added to allow you to break on nested functions. See the GHC 9.0.1 user guide. E.g.:

> :break f.g

For earlier versions of GHC, you could perhaps add a special debugging variable:

debugBreak = True

f x =
    let g x' y | debugBreak =
        let -- ...
        in -- ...
    in -- ...

Then you can break on that function like this:

> :break debugBreak

And just do a single step when you hit that break point.

Related