Hi,

are you aware of the QuotationEvaluation module in FSharp.PowerPack.Linq ? It allows you to compile quotations to F# code.

(Old documentation for previous version: [link:research.microsoft.com] )

You could try to find out how that module handles the function call case, e.g. by looking at the source code here: [link:fsharppowerpack.codeplex.com]

Or maybe the functionality of this module is already all that you need.

Hope this helps,

Wolfgang

By on 5/16/2011 9:55 AM ()

Thanks for your answer.

I'm aware of the Link module. Actually when I read this post ([link:stackoverflow.com] I decided no to use it because it says that the performances are 50 to 700 times slower than the version produced by the F# compiler.

I took a look to the source code as you suggested and apparently the F# expression is converted into a Linq expression and then compiled using the existing Compile method:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
    let CompileImpl (e: #Expr, eraseEquality) = 

       let ty = e.Type

       let e = Expr.NewDelegate(GetFuncType([|typeof<unit>; ty |]), [new Var("unit",typeof<unit>)],e)

       // Convert...

       let linqExpr = Conv (e,eraseEquality)

       let linqExpr = (linqExpr :?> LambdaExpression)

      // ...and compile

       let d = linqExpr.Compile()

       (fun () -> 

           try 

             d.DynamicInvoke [| box () |]

           with :? System.Reflection.TargetInvocationException as exn -> 

               raise exn.InnerException)

    let Compile (e: #Expr) = CompileImpl(e,false)

EntraX

By on 5/16/2011 10:18 AM ()

I think I can get the method's attributes and check if this attribute exists:

CompilationArgumentCountsAttribute:

This attribute is generated automatically by the F# compiler to tag functions and members that accept a partial application of some of their arguments and return a residual function

By on 5/16/2011 10:40 AM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper