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

  • Home
  • SEARCH
  • 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 9132275
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:17:04+00:00 2026-06-17T08:17:04+00:00

Is there any way to determine whether a given type parameter satisfies the F#

  • 0

Is there any way to determine whether a given type parameter satisfies the F# comparison constraint through reflection?

I would suspect not, since the expression

typedefof<Set<_>>.MakeGenericType [| typeof<System.Type> |]

appears to yield no errors. Still, I would like to hear some authoritative opinion on this.

  • 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-06-17T08:17:06+00:00Added an answer on June 17, 2026 at 8:17 am

    Quoting from Don Syme’s thorough post on equality and comparison constraints:

    The constraint type : comparison holds if:

    • if the type is a named type, then the type definition doesn’t have the NoComparison attribute; and
    • the type definition implements System.IComparable; and
    • any “comparison dependencies” of the type also satisfy tyi : comparison

    The constraint 'T when 'T :> IComparable can be encoded in CIL and reflected upon, whereas neither is true of 'T when 'T : comparison.

    Since the two constraints are not equivalent, marking comparable types with the IComparable constraint is a bit misleading since it would make it impossible to distinguish between the two using reflection.

    There’s a similar relationship between the equality constraint and IEquatable<_>.

    EDIT

    Jack’s mention that the comparison constraint could be encoded in F# metadata prompted me to look at the metadata reader in PowerPack. It can be used to detect the constraint:

    open Microsoft.FSharp.Metadata
    
    let setEntity = FSharpAssembly.FSharpLibrary.GetEntity("Microsoft.FSharp.Collections.FSharpSet`1")
    for typeArg in setEntity.GenericParameters do
      printfn "%s - comparison=%b" 
        typeArg.Name 
        (typeArg.Constraints |> Seq.exists (fun c -> c.IsComparisonConstraint))
    

    Here’s a contrived example that shows the disparity between implementing IComparable and satisfying comparison:

    type A() = 
      interface IComparable with
        member __.CompareTo(_) = 0
    
    [<NoComparison>]
    type B() =
      inherit A()
    
    type C<'T when 'T : comparison>() = class end
    type D<'T when 'T :> IComparable>() = class end
    
    let c = C<B>() //ERROR
    let d = D<B>() //OK
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given an ActionScript Function object, is there any way to determine whether that function
Is there any way in Oracle to determine whether a package has state or
Is there any way in Android to determine whether a device is running Sense
is there any way to validate using ModelState and model, to determine the type
Is there any way to determine whether the browser is using hardware acceleration for
Is there any way to determine whether a buffer received as a void* pointer
Is there any way to determine whether the Accelerate.framework is available at runtime from
Is there any way to determine whether FirePHP is installed on the server (via
Is there any way to determine whether a linux executable is using soft float
Is there any way to determine in javascript whether shift key is pressed on

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.