EDIT: From the answer and comments added so far that I did not correctly explain what I want. Here is an example:
[<NoEquality>]
[<NoComparison>]
type blah () =
member x.huha = 0
let inline tt x =
Map.ofList [1, x]
let test () =
if (tt 1 = tt 2) then failwithf "strange"
if (tt (blah ())).Count <> 1 then failwithf "size"
if tt (blah ()) = tt (blah ()) then ....
In short, I want my own type to behave just like the map above. Therefore, it must maintain equality when the type argument does, and should not when the type argument does not work. I also want typechecker to stop me using equality when it is not supported, since it can explicitly do this for built-in types. Thanks again.
: F # , . , Map<'k, 'd> iff 'd ( ). ? , , . .
[<NoComparison>]
type test_fails<[<EqualityConditionalOn>]'a> (content:'a) =
let eq_impl (x:test_fails<'a>) (y:obj) =
let y = y :?> test_fails<'a>
x.content = y.content
member x.content = content
override x.Equals (y:obj) =
eq_impl x y
[<NoComparison>]
type test_compiles<'a when 'a : equality> (content:'a) =
let eq_impl (x:test_compiles<'a>) (y:obj) =
let y = y :?> test_compiles<'a>
x.content = y.content
member x.content = content
override x.Equals (y:obj) =
eq_impl x y