I started coding in F# about 2 months ago.
I am greatly enjoying this programming language. I come from a C# background, and every time I need to revert back to C#,
The question of improving debugging experience with F# has many aspects so it deserves a big article. So I'm afraid the question will be closed.
Nevertheless, here are two neat tricks I'm using. I must note that I'm also a big fan of pipeline approach and so I'm facing exactly the same problems.
Know your types.
Having a value threaded through a chain of many transformations may quickly lead to difficulty remembering exact types at each step. The trick is:
value
|> transformation1
|> fun x -> x
|> transformation2
This lets you:
x
in design time;Conditionally dump the values to console.
Having complicated lambdas, breakpoints may be of little help. Here's yet another trick, related to the one described in @Tomas' answer: write a small function, like this:
let inline debug x =
#if DEBUG
if System.Console.CapsLock then
printfn "%A" x
// obviously, it must not be necessarily printf;
// it can be System.Diagnostics.Debug.WriteLine()
// or any other logger tool that exists in the project.
#endif
x
The usage code looks like this:
value
|> transformation1
|> fun x -> x
|> debug
|> transformation2
The idea is that:
debug
call, just as described above;If you have multiple places where debug
call sit, they would not spoil the output.