How to get the name of a higher order function in F #?

let Sigmund () = 
    System.Reflection.MethodBase.GetCurrentMethod().Name
let Donald () = 
    System.Reflection.MethodBase.GetCurrentMethod().Name
let Eustachio () = 
    System.Reflection.MethodBase.GetCurrentMethod().Name

let get_name_of_x (x: unit -> unit) =
    //System.Reflection.???
    ()

let x = 
    [|
    Sigmund
    Donald
    Eustachio
    |]

x |> Array.iter (fun x -> x() |> printfn "%s") // prints all the names

Since functions can see their name, I know that it should be possible to get the name of the function passed to get_name_of_x, but I cannot figure out how to do this. Being able to do this would be helpful when writing my own testing library.

Fuchu , for example, does not separate names directly from functions, and using DU for composition instead of functions makes it less flexible than it could be, so it might be worth improving.

+4
source share

Source: https://habr.com/ru/post/1653520/


All Articles