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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T08:34:46+00:00 2026-05-14T08:34:46+00:00

In F#, the equality operator (=) is generally extensional, rather than intensional. That’s great!

  • 0

In F#, the equality operator (=) is generally extensional, rather than intensional. That’s great! Unfortunately, it appears to me that F# does not use pointer equality to short-cut these extensional comparisons.

For instance, this code:

type Z = MT | NMT of Z ref

// create a Z:
let a = ref MT
// make it point to itself:
a := NMT a

// check to see whether it's equal to itself:
printf "a = a: %A\n" (a = a)

… gives me a big fat segmentation fault[*], despite the fact that ‘a’ and ‘a’ both evaluate to the same reference. That’s not so great. Other functional languages (e.g. PLT Scheme) get this right, using pointer comparisons conservatively, to return ‘true’ when it can be determined using a pointer comparison.

So: I’ll accept the fact that F#’s equality operator doesn’t use short-cutting; is there some way to perform an intensional (pointer-based) equality check? The (==) operator is not defined on my types, and I’d love it if someone could tell me that it’s available somehow.

Or tell me that I’m wrong in my analysis of the situation: I’d love that, too…

[*] That would probably be a stack overflow on Windows; there are things about Mono that I’m not that fond of…

  • 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-14T08:34:47+00:00Added an answer on May 14, 2026 at 8:34 am

    There are two options that I’m aware of. The standard .NET approach would be to use System.Object.ReferenceEquals. A slightly better approach in F# might be to use LanguagePrimitives.PhysicalEquality which is basically identical, but only works on reference types (which is probably correct for your purposes) and requires both arguments to have the same static type. You can also define a custom operator of your choice in terms of either of these functions if you’d like nicer syntax.

    As an aside, on .NET I get an infinite loop but not a stack overflow when I run your code, presumably due to tail call optimization.

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

Sidebar

Related Questions

Is there way to test for both 0 and NULL with one equality operator?
Is it possible to provide an implementation for the C# equality (==) operator in
If I have a table where certain fields are always searched using an equality
I have a method that takes an System.Action, this is what I'm trying to
I'm creating result paging based on first letter of certain nvarchar column and not
I lack industry experience with the language. But in my spare time I have
int main (int argc, **argv) { if (argv[1] == -hello) printf(True\n); else printf(False\n); }
I'm trying to write a Linq query which returns an array of objects, with
This might be a silly question, but here goes : I hashed a dictionary
The code is as follows template<class T> class arrayList { public: // constructor, copy

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.