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 7248055
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T22:05:15+00:00 2026-05-28T22:05:15+00:00

I am trying to call a c# function from f# where the c# function

  • 0

I am trying to call a c# function from f# where the c# function takes a function (delegate?) as a parameter and I need this argument to be a f# function. Eg:

Sample c#

public static void function_1(double x, ref double y)
{
    y = Math.Exp(x);
}

main()
{ 
    state s;
    call_func(s, function_1)
}

So, call_func has a parameter of type void fn(double, ref double)

In f# I tried:

let function_1 (x:double) (y:double byref) = 
    let y = 6.0
    ()

let test = 
    let s = new state
    let ret = call_func(s, function_1)

But I get the error that the f# function_1 has type double -> double byref -> unit when it should be the type of the delegate void fn(double, ref double).

Can I cast the type or something like that? Or is there an error?

  • 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-28T22:05:16+00:00Added an answer on May 28, 2026 at 10:05 pm

    If you want to create a delegate from a function in F#, you can use the new operator and give it the function as an argument:

    let function_1 (x:double) (y:double) = 
        ()
    
    Program.call_func(s, new Action<double, double>(function_1))
    

    But, for some reason, if try to use the same approach with a delegate that contains ref, you get this error:

    This function value is being used to construct a delegate type whose signature includes a byref argument. You must use an explicit lambda expression taking 2 arguments.

    So, if you follow the advice given by the error message, you can write the following:

    let function_1 (x:double) (y:double byref) = 
        y <- 6.0
    
    Program.call_func(s, new fn(fun x -> fun y -> function_1 x &y))
    

    This compiles, and works as expected.

    Note that to modify the parameter y, you have to use the <- operator. Using let y = 6.0 declares completely different variable that shadows the parameter.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Has anyone seen this error when trying to call an external C function from
I'm trying to call an external Delphi function from C# which takes a Delphi
i am trying to call a legacy function, which takes normal pointer parameter, with
I'm trying to call a function from a form within the same .php file,
I am trying to call my function named isUrgencyTypeValid from my javascript code but
I'm trying to call a function in a Python script from my main C++
I'm currently trying to register a JS function call from a .NET page which
I'm trying to call from C# a function in a custom DLL written in
I am trying to call a setTimeout from within a setInterval callback: function callback()
I'm having a weird issue with a function I'm trying to call from within

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.