Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 754499
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T15:01:15+00:00 2026-05-14T15:01:15+00:00

I can convert a quotation of type Expr<‘a -> ‘b> to a Linq expression

  • 0

I can convert a quotation of type Expr<'a -> 'b> to a Linq expression via the following snippet:

/// Converts a F# Expression to a LINQ Lambda
let toLambda (exp:Expr) =
    let linq = exp.ToLinqExpression() :?> MethodCallExpression
    linq.Arguments.[0] :?> LambdaExpression

/// Converts a Lambda quotation into a Linq Lamba Expression with 1 parameter
let ToLinq (exp : Expr<'a -> 'b>) =
    let lambda = toLambda exp
    Expression.Lambda<Func<'a, 'b>>(lambda.Body, lambda.Parameters)

Now I want to convert a quotation of type Expr<'a * 'b -> 'c> or maybe even Expr<'a -> 'b -> 'c> to a Linq Lambda Expression of type Expression<Func<'a,'b'c>>.

How can I do this?

Regards,
forki

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T15:01:15+00:00Added an answer on May 14, 2026 at 3:01 pm

    I’m not sure if this is directly supported by the LINQ modules available in the F# PowerPack. However, you can implement your own post-processing of the LINQ expression produced by F# libraries to turn it into a C# lambda function of the usual form:

    The following function takes a LINQ expression which is constructed as multiple nested LambdaExpression expressions of a single parameter (that is, the structure produced by F# translator) and returns a list of parameters and body of the inner-most expression:

    let rec translateExpr (linq:Expression) = 
      match linq with
      | :? MethodCallExpression as mc ->
          let le = mc.Arguments.[0] :?> LambdaExpression
          let args, body = translateExpr le.Body
          le.Parameters.[0] :: args, body
      | _ -> [], linq
    

    Now you can use it to get an ordinary Func delegate out of type such as int -> int -> int -> int like this:

    let linq = (<@@ fun a b c -> (a + b) * c @@>).ToLinqExpression()
    let args, body = translateExpr liq
    let f = Expression.Lambda<Func<int, int, int, int>>
              (body, args |> Array.ofSeq)
    f.Compile().Invoke(10, 11, 2)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a tool out there which can convert SQL syntax to LINQ syntax?
Anyone know how I can convert Request.Cookies into a List<HttpCookie> ? The following didn't
Is there can convert the stuff read from input port to some specific type
Where can I find a code snippet which can convert a DataGridView to a
How can I create the mod_rewrite rule so I can convert the following URLs:
Just as you can convert the following: var t; if(foo == bar) { t
How I can convert this code to LINQ? var TcData = new List<double>(); for(int
I do not think I can convert the following: List<B> c = new ArrayList<B>();
is there any way i can convert below syntax to LINQ equivalent. select DateName(
I can convert RGB values to HSV with the following code... $r = $r/255;

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.