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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T01:00:45+00:00 2026-05-20T01:00:45+00:00

I need to understand something very important regarding F#: how it handles references and

  • 0

I need to understand something very important regarding F#: how it handles references and values.
I know that F# defines immutable and mutable objects and also know the reason why.

But there is one thing that I do not know: how are objects treated?

I mean, in C# everything is a pointer and when assigning to an object the reference of another one, data are the same, and we’ll have two pointers pointing the same data.

So in C# if I have this:

Object myobj1 = new Object();
Object myobj2 = myobj1;
bool myobj1 == myobj2; // It is true

Well, what about f#?

let myvar: MyObj = new MyObj ()
let myvar2: MyObj = myvar

What’s the situation here?
Does the assignment involves copy? or not.

And, generally speaking, what’s f# approach to this topic? (I mean value vs reference).

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

    When working with reference types and value types, F# behaves just like C#.

    • When you have a reference type, it works with a reference to an instance in the heap.
    • When you have a value type (built-in, declared in C# or declared in F# using Struct attribute),
      the value is copied when you assign it to another value or pass as argument.

    The only notable difference is that standard F# types (discriminated unions, records, lists, arrays and tuples) have structural equality semantics. This means that they are compared by comparing the actual value stored in them and not by comparing references (even if they are reference types). For example, if you create two lists of tuples containing the same data you get:

    > let l1 = [ ("Hello", 0); ("Hi", 1) ]
      let l2 = [ ("Hi", 1); ("Hello", 0) ] |> List.rev;;
    (...)
    
    > l1 = l2;;
    val it : bool = true
    

    You get true even though lists and tuples are reference types. If you compare the references however (EDIT: Added sample inspired by kvb):

    > System.Object.ReferenceEquals(l1, l2);;
    val it : bool = false
    

    The use of structural equality makes sense in F# because the types are immutable – when you create two values containing the same data, they will always be the same. If they were mutable, you could change one and they wouldn’t be equal anymore – that’s why it makes more sense to use reference equality for mutable types.

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

Sidebar

Related Questions

What are the top 3 main concepts in WPF that you need to understand
I don't know if this is a right question, but i need to understand
I understand the need to test a class that has logic (for instance, one
I understand that I need to use LoadLibrary(). But what other steps do I
I know now, that if I need to get a recource in some static
I have a very simple problem in which I need to do something after
I'm interested in teaching myself different data structures, something I currently know very little
I feel like an idiot, because i fight with something, that should be very
what I need is something very alike QtMessageBox.information method, but I need it form
I understand that this question is based on a very old programming language, and

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.