3 people like it.

Get the name of function

1: 
2: 
3: 
4: 
5: 
6: 
7: 
8: 
9: 
open Microsoft.FSharp.Quotations

let rec funName = function
| Patterns.Call(None, methodInfo, _) -> methodInfo.Name
| Patterns.Lambda(_, expr) -> funName expr
| _ -> failwith "Unexpected input"

let foo () = 42
funName <@ foo @>       // "foo"
namespace Microsoft
namespace Microsoft.FSharp
namespace Microsoft.FSharp.Quotations
val funName : _arg1:Expr -> string

Full name: Script.funName
module Patterns

from Microsoft.FSharp.Quotations
active recognizer Call: Expr -> (Expr option * System.Reflection.MethodInfo * Expr list) option

Full name: Microsoft.FSharp.Quotations.Patterns.( |Call|_| )
union case Option.None: Option<'T>
val methodInfo : System.Reflection.MethodInfo
property System.Reflection.MemberInfo.Name: string
active recognizer Lambda: Expr -> (Var * Expr) option

Full name: Microsoft.FSharp.Quotations.Patterns.( |Lambda|_| )
val expr : Expr
val failwith : message:string -> 'T

Full name: Microsoft.FSharp.Core.Operators.failwith
val foo : unit -> int

Full name: Script.foo
Raw view Test code New version

More information

Link:http://fssnip.net/qv
Posted:10 years ago
Author:
Tags: