How to Get the F# Name of a Module, Function, etc. From Quoted Expression Match

Posted by Stephen Swensen on Stack Overflow See other posts from Stack Overflow or by Stephen Swensen
Published on 2011-01-05T12:49:40Z Indexed on 2011/01/05 12:54 UTC
Read the original article Hit count: 167

Filed under:

I continue to work on a printer for F# quoted expressions, it doesn't have to be perfect, but I'd like to see what is possible. The active patterns in Microsoft.FSharp.Quotations.Patterns and Microsoft.FSharp.Quotations.DerivedPatterns used for decomposing quoted expressions will typically provide MemberInfo instances when appropriate, these can be used to obtain the name of a property, function, etc. and their "declaring" type, such as a module or static class. The problem is, I only know how to obtain the CompiledName from these instances but I'd like the F# name. For example,

> <@ List.mapi (fun i j -> i+j) [1;2;3] @> |> (function Call(_,mi,_) -> mi.DeclaringType.Name, mi.Name);;
val it : string * string = ("ListModule", "MapIndexed")

How can this match be rewritten to return ("List", "mapi")? Is it possible?

© Stack Overflow or respective owner

Related posts about F#