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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T01:47:24+00:00 2026-05-17T01:47:24+00:00

Is there a way to have mutable function arguments in F#, that would allow

  • 0

Is there a way to have mutable function arguments in F#, that would allow something like

let mutable i = 9

let somefun n = n <- 12; ()

somefun i

(* *not* a real-world example *)

I do understand that this can be made to work by wrapping it into a record type

type SomeRec = { mutable i: int }

let ri = { i = 9 }

let someotherfun r = r.i <- 12; ()

and that this can be done in a similar fashion for class members. However, even after browsing through the whole F# Language Specification (yes, I did!), there seems to be no syntax to allow the first case, and the compiler appears to be quite unhappy about my trying this. I was hoping there would be some sort of type annotation, but mutable cannot be used in such.

I also know that I should not be doing this sort of thing in the first place, but the first case (int binding) and the second (record type) are semantically identical, and any such objection would hold for both cases equally.

So I think that I am missing something here.

  • 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-17T01:47:25+00:00Added an answer on May 17, 2026 at 1:47 am

    You can use ref as arguments

    let v = ref 0
    let mutate r = 
        r := 100
    mutate v
    printfn "%d" !v
    

    Or byref keyword

    let mutable v = 0
    let mutate (r : byref<_>) = 
        r <- 100
    mutate &v
    printfn "%d" v
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any way to have a default MessageBox.Show() caption? Let says I would
Is there a way to have setup/teardown code automagically run before/after each test? Something
I would like to create a function using Linq that summarizes an incoming sequence
If I have a data tree that is something like : NSMutableDictionary (dict1) NSMutableDictionary
Is there a way, using a TRIGGER or preferably some MySql function I'm not
I have a mutable HashMap and would like to use it like a default-dictionary.
Is there a way to have a template specialization based on a range of
Is there a way to have ASP classic cdonts email, have an file attached
Is there a way to have hanging operators when indenting with tabs in Vim?
Is there a way to have rails print out a number with commas in

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.