Is there a way in F# to create a function that takes any other function as its sole parameter and return that function's body text as the result?
For example:
let myFunc =
// Always equals 3!
let x = 1 + 2
// Print it to the console
printfn "x = %i" x
let extractFunctionText f =
???
extractFunctionText myFunc
extractFunctionText
should have a signature of ('a -> 'b) -> string
i.e. it will take any function as an input and returns a string. The string I'd like returned in the last line of specific example above is:
"""// Always equals 3!
let x = 1 + 2
// Print it to the console
printfn "x = %i" x"""
Apologies for any typos or naive questions: I'm a bit of a newb at this. I think that following links (SO Answer & MSDN) get me quite close but I don't understand things well enough to finish the job