I am converting several modules based on OCaml to F#. I have the code converted and running in F#, however the result of the final function in F# is not the same as the result of the final function in OCaml. So obviously I have to follow the function calls to figure out which function is returning the wrong result.
OCaml has a nice top-level directive for tracing the input and output of a function, i.e. #trace .
I have searched F#’s debug and trace methods and the closest I get is to instrument the code using Trace.Write methods but it takes several lines for each method.
e.g.
Original
let fun001 parm001 =
parm001 * 10
Instrumented
let fun001 parm001 =
// For VS 2010, this trace output will be sent to Output window.
System.Diagnostics.Trace.WriteLine("function001 <--");
System.Diagnostics.Trace.WriteLine(sprintf "%A" parm001);
let result = parm001 * 10
System.Diagnostics.Trace.WriteLine("function001 -->");
System.Diagnostics.Trace.WriteLine(sprintf "%A" result);
result
Does F# have the same functionality as OCaml #trace that I missed when searching?
If you are sure the answer is no, that’s all I need. I know people frown on short answers, but that is all I need if the answer is no.
EDIT
For more complex methods where capturing the result would evolve extensive modification to the code
Original
let func001 parm001 parm002 =
match parm001 with
| pattern001 -> func002 parm002
| head :: tail ->
func003 head
func001 tail
| [] -> failwith "failed"
Instrumented
let func001org parm001 parm002 =
match parm001 with
| pattern001 -> func002 parm002
| head :: tail ->
func003 head
func001 tail
| [] -> failwith "failed"
and fun001 parm001 parm002 =
// For VS 2010, this trace output will be sent to Output window.
System.Diagnostics.Trace.WriteLine("function001 <--");
System.Diagnostics.Trace.WriteLine(sprintf "%A, %A" parm001 parm002 );
let result = func001org parm001 parm002
System.Diagnostics.Trace.WriteLine("function001 -->");
System.Diagnostics.Trace.WriteLine(sprintf "%A" result);
result
EDIT
PostSharp does not support F#. See: Using PostSharp with F# – Need documentation with working example
No (although I would love to have such a facility in F#).