Converting OCaml to F #: Is there an easy way to simulate #trace top-level OCaml in F #

I am converting several OCaml-based modules to F #. I have code converted and run in F #, however the result of the final function in F # does not match the result of the final function in OCaml. Therefore, obviously, I need to follow function calls to figure out which function returns the wrong result.

OCaml has a beautiful top-level directive to track function input and output, i.e. # trace .

I searched for F # debug and trace , and the closest I use a method that uses the Trace.Write methods, but each method requires a few lines.

eg.

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

F # , OCaml #trace, ?

, , , . , , , , .

, ,

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

PostSharp F #. : PostSharp F # -

+5
2

( F #).

+3

F # , , .

PostSharp. - ( , ). , . , F #, , .

PostSharp, , ( #trace OCaml), , . - ( ).

+5

All Articles