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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T21:21:07+00:00 2026-05-22T21:21:07+00:00

I am struggling to expose comparison/equality on a union type whose cases are hidden.

  • 0

I am struggling to expose comparison/equality on a union type whose cases are hidden. This is what I started with:

Module.FSI

type A<'T when 'T : comparison>

Module.FS

type A<'T when 'T : comparison> = A of 'T list

Program.FS

[<StructuralEquality;StructuralComparison>]
type B =
    | Case1
    | Case2 of Module.A<char>

But I get the error:

The struct, record or union type 'B' has the 'StructuralComparison'
attribute but the component type 'Module.A<char>' does not satisfy the
'comparison' constraint

I’ve tried using custom equality on A:

Module.FSI

[<CustomEquality;CustomComparison>]
type A<'T when 'T : comparison>
  with
    interface System.IComparable
    override Equals : y:obj -> bool
    override GetHashCode : unit -> int
  end

Module.FS

[<CustomEquality;CustomComparison>]
type A<'T when 'T : comparison> = A of 'T list
    with
        override x.Equals y = ...
        override x.GetHashCode() = ...
        interface System.IComparable with
            member x.CompareTo(y) = ...

But I get this:

This construct is deprecated: The syntax 'type X with ...' is reserved 
for augmentations. Types whose representations are hidden but which have
 members are now declared in signatures using 'type X = ...'.

Is this the right way to go about exposing comparison from an union type with private cases? What is the correct syntax for this in signature files?

  • 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-22T21:21:08+00:00Added an answer on May 22, 2026 at 9:21 pm

    The error message only says that the correct syntax for the FSI file declarations should use = (as in the implementation file) instead of the with ... end syntax. However, that doesn’t really solve the problem. After some experimantations, I think you don’t need to apply the attributes in the FSI file:

    // Mod.fs
    namespace Mod
    
    [<CustomEquality; CustomComparison>] //; CustomEquality>]
    type A<'T when 'T : comparison> = 
      | A of 'T list    
      override x.Equals y = compare x (y :?> A<_>) = 0
      override x.GetHashCode() = -1
      interface System.IComparable with
        member x.CompareTo(y) = compare x (y :?> A<_>)
    
    // Mod.fsi
    namespace Mod
    
    [<Sealed>]
    type A<'T when 'T : comparison> =
      interface System.IComparable
      override Equals : obj -> bool
      override GetHashCode : unit -> int
    

    This should do the trick – unfortunatelly, I’m not sure if there is a way to use automatically generated structural equality and hide the implementation of the discriminated union at the same time.

    EDIT It looks like you can specify the discriminated union cases in the FSI file, but mark them as private, so they won’t be visible outside of the module. So maybe this would work too:

    // Mod.fsi
    namespace Mod
    
    type A<'T when 'T : comparison> = 
      private | A of 'T list    
    
    // Mod.fs
    namespace Mod
    
    [<StructuralComparisonAttribute; StructuralEqualityAttribute>] 
    type A<'T when 'T : comparison> = 
      | A of 'T list    
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Struggling a bit on this... I'm using crontab for a lot of todo list
Been struggling with this simple selector problem a couple of hours now and must
im struggling with syntax here: hopefully this question is v simple, im just miising
A coworker has been struggling with this problem. The desired result is an installable
I'm still struggling with this concept. I have two different Person objects, very simply:
Struggling with this one. I have set up a basic email/enquiry form for a
Struggling with this tournament fixtures algorithm. The code is working perfectly but I need
Struggling with this problem for an hour now and searched both stackoverflow and google
Just struggling with a simple issue with ASP.NET MVC. I have a list of
struggling to get my head round this. i want to convert the following sql

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.