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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T23:53:40+00:00 2026-05-13T23:53:40+00:00

I am currently implementing a Spec framework in F# and I want to hide

  • 0

I am currently implementing a Spec framework in F# and I want to hide the Equals, GetHashCode etc. methods on my should type, so that the API is not cluttered with these.

I know in C# it is done by making the class implement an interface like this:

using System;
using System.ComponentModel;

public interface IFluentInterface
{
    [EditorBrowsable(EditorBrowsableState.Never)]
    bool Equals(object other);

    [EditorBrowsable(EditorBrowsableState.Never)]
    string ToString();

    [EditorBrowsable(EditorBrowsableState.Never)]
    int GetHashCode();

    [EditorBrowsable(EditorBrowsableState.Never)]
    Type GetType();
}

I tried doing the same in F#:

type IFluentInterface = interface

    [<EditorBrowsable(EditorBrowsableState.Never)>]
    abstract Equals : (obj) -> bool

    [<EditorBrowsable(EditorBrowsableState.Never)>]
    abstract ToString: unit -> string

    [<EditorBrowsable(EditorBrowsableState.Never)>]
    abstract GetHashCode: unit -> int

    [<EditorBrowsable(EditorBrowsableState.Never)>]
    abstract GetType : unit -> Type 
end

Implemented it in my type:

        interface IFluentInterface with
        member x.Equals(other) = x.Equals(other)
        member x.ToString()    = x.ToString() 
        member x.GetHashCode() = x.GetHashCode()
        member x.GetType()     = x.GetType() 

but without success.

I also tried to override the methods in my type and adding the attribute that way, but that didn’t do the trick either.

So the question remains, how can I clean up my API ?

Edit:

Thanks to the help (see below) I was able to solve my problem.

In summary, .Equals and .GetHashCode can be hidden via [<NoEquality>] [<NoComparison>] but that will also change the semantics.

The hiding via EditorBrowsable attributes does not work.

The only way to have a clean API and still be able to overload methods is to make these method members static.

The resulting class can be found by browsing inside my project FSharpSpec.

The type in question can be found here.

Thanks to everyone who helped me solve this problem.

Cheers …

  • 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-13T23:53:40+00:00Added an answer on May 13, 2026 at 11:53 pm

    Alternatively, you could design the library using an alternative style using functions enclosed in a module. This is the usual way for writing functional code in F# and then you won’t need to hide any standard .NET methods. To complete the example given by ‘kvb’, here is an example of object-oriented solution:

    type MyNum(n:int) =
      member x.Add(m) = MyNum(n+m)
      member x.Mul(m) = MyNum(n*m)
    
    let n = new MyNum(1)
    n.Add(2).Mul(10) // 'ToString' shows in the IntelliSense
    

    The functional way of writing the code might look like this:

    type Num = Num of int
    module MyNum =
      let create n = Num n
      let add m (Num n) = Num (m + n)
      let mul m (Num n) = Num (m * n)
    
    MyNum.create 1 |> MyNum.add 2 |> MyNum.mul 10
    

    If you type MyNum., the F# IntelliSense will show the functions defined in the module, so you won’t see any noise in this case.

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

Sidebar

Related Questions

I'm currently implementing a radix tree/patricia trie (whatever you want to call it). I
I'm currently implementing a JavaScript library that keeps track of the history of changes
I'm currently implementing a Monotouch application that will eventually be ported to Monodroid. The
I'm currently working on implementing the public API of our web application. The application
I am implementing a RESTful web service that currently handles JSON and needs to
I'm currently implementing a raytracer. Since raytracing is extremely computation heavy and since I
I've been looking at the DropBox Mac client and I'm currently researching implementing a
I am currently having a hardtime understanding and implementing events in C# using delagates.
I'm currently in the process of implementing a number of different assignment algorithms for
I'm implementing a document server. Currently, if two users open the same document, then

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.