I am currently implementing the Spec framework in F # and I want to hide the Equals, GetHashCode methods, etc. in my type should, so the API will not clutter them.
I know that in C # this is done by implementing a class with this interface:
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 to do 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 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 add the attribute this way, but that didn't help either.
So the question remains, how can I clear my API?
Edit:
Thanks to the help (see below), I was able to solve my problem.
This way, .Equalsand .GetHashCodecan be hidden using [<NoEquality>] [<NoComparison>], but it will also change the semantics.
Hiding with EditorBrowsable attributes does not work.
API - - .
, FSharpSpec.
, , .
, .
...