Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Debugging F# code and functional style

Tags:

I'm new to funcctional programming and have some questions regarding coding style and debugging.

I'm under the impression that one should avoid storing results from funcction calls in a temp variable and then return that variable

e.g.

let someFunc foo =     let result = match foo with                  | x -> ...                  | y -> ...     result  

And instead do it like this (I might be way off?):

let someFunc foo =     match foo with     | x -> ...     | y -> ... 

Which works fine from a functionallity perspective, but it makes it way harder to debug. I have no way to examine the result if the right hand side of -> does some funky stuff.

So how should I deal with this kind of scenarios?

like image 503
Roger Johansson Avatar asked Apr 23 '10 07:04

Roger Johansson


1 Answers

To inspect the middle of a pipeline, I suggest the following workaround:

Put this code at some place:

[<AutoOpen>] module AutoOpenModule  #if DEBUG let (|>) value func =   let result = func value   result #endif 

Enable "Step Into Properties and Operators in Managed Code":

https://msdn.microsoft.com/en-us/library/cc667388(v=vs.100).aspx

Now you should be able to step into the pipeline operator.

like image 126
Oldrich Svec Avatar answered Oct 25 '22 07:10

Oldrich Svec