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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T05:05:53+00:00 2026-05-29T05:05:53+00:00

Under normal circumstances, F# functions can be converted to delegates by calling new DelegateType

  • 0

Under normal circumstances, F# functions can be converted to delegates by calling new DelegateType and passing in the function as an argument. But when the delegate contains byref parameter, this is not possible directly. For example the code:

type ActionByRef<'a> = delegate of 'a byref -> unit

let f (x:double byref) = 
    x <- 6.0

let x = ref 42.0
let d = new ActionByRef<_>(f)

won’t compile, giving the following 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 1 arguments.

Following the error, modifying the code to use

let d = new ActionByRef<_>(fun x -> f(&x))

works. But my question is: why is this necessary? Why won’t F# allow the conversion from named function to this delegate, but conversion from lambda is fine?

I came upon this behavior when researching another question. I realize byref is meant only for compatibility with other .Net languages.

  • 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-29T05:05:55+00:00Added an answer on May 29, 2026 at 5:05 am

    I think the problem is that byref<'T> is not an actual type in F# – it looks like a type (to make the language simpler), but it gets compiled to a parameter marked with the out flag. This means that byref<'T> can be only used in a place where the compiler can actually use the out flag.

    The problem with function values is that you can construct function e.g. by partial application:

    let foo (n:int) (b:byref<int>) = 
      b <- n
    

    When you pass foo as an argument to a delegate constructor, it is a specific case of partial application (with no arguments), but partial application actually needs to construct a new method and then give that to the delegate:

    type IntRefAction = delegate of byref<int> -> unit  
    
    let ac = IntRefAction(foo 5)
    

    The compiler could be clever and generate new method with byref parameter (or out flag) and then pass that by reference to the actual function, but in general, there will be other compiler-generated method when you don’t use the fun ... -> ... syntax. Handling this would add complexity and I think that’s a relatively rare case, so the F# compiler doesn’t do that and asks you to be more explicit…

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

Sidebar

Related Questions

Under normal circumstances, a VB.NET application of mine can check the ClientName environmental variable
I have an installshield installer that works fine under normal circumstances. But when I
Expected Behavior Under normal circumstances, I can issue tshark -E separator='@' under linux See
On Windows, under normal circumstances a 32 bit process can only access 2GB of
We have software that runs fine under a normal Windows installation but when we
Under normal circumstances to authenticate a user in AD, one sends AD the user's
Will the Android OS kill my IntentService under normal circumstances or do I need
We've got a winforms LOB application, which under normal circumstances should be started from
A project I'm working on requires detection of duplicate files. Under normal circumstances I
Under normal circumstances, what should I expect the worse case scenario to be for

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.