F# quotations at their simplest
02 Apr 2009 06:49 PM UncategorizedQuick blurb, more later. This is simply cool. 5 lines of code that can give you the signature of a function, with parameter names.
open Microsoft.FSharp.Quotations.Patterns open Microsoft.FSharp.Quotations.DerivedPatterns [<ReflectedDefinition>] let sample f_name p2 = printf "sample {%A}\r\n" f_name let rec get_parms exp = match exp with | Lambda (var,body) -> [var.Name.[..var.Name.IndexOf("@")-1]] @ get_parms body | _ -> [] List.iter (printf "%A\r\n") (get_parms <@ sample @>) ignore <| System.Console.Read()
the cool thing is that because of the ReflectedDefinition attribute, I can use "sample" as both a quotation and a regular function.
Jeebus.
0 Reply to “F# quotations at their simplest”