I have a simple F# type as follows:
(* Num.fsi *)
namespace FsLib
module Num =
[<NoEquality>]
type t
val of_int : int -> t
val to_int : t -> int
Implementation is trivial as you might imagine, it's just a single-case
discriminated union with an underlying int
. Now in a C# project in the
same solution I have the following code:
// CsTool.cs
using System;
using FsLib;
namespace CsTool {
class MainClass {
public static void Main(string[] args) {
Num.t n1 = Num.of_int(1);
Num.t n2 = Num.of_int(1);
Console.WriteLine(n1.Equals(n2));
}
}
}
The problem is, this is printing False
instead of failing to compile
or throwing a runtime error. Any idea why this C# calling code is
ignoring the [<NoEquality>]
attribute?
By the way I am running this in Xamarin Studio Community on Mac, version 6.1.2, targeting .NET Framework version 4.5.1.
NoEqualityAttribute
? Basically, that's not a cross-language-implemented attribute. You could potentially write a Roslyn analyzer to catch calls like that though.