2

F# compiler does a lot of work for us. By default it implements IComparable<T>.

However, the code is embarrassing

type Either = | This | That

Yields:

[CompilerGenerated]
public sealed override int CompareTo(Either obj)
{
    if (this != null)
    {
        if (obj != null)
        {
            int tag = _tag;
            int tag2 = obj._tag;
            if (tag == tag2)
            {
                return 0;
            }
            return tag - tag2;
        }
        return 1;
    }
    if (obj != null)
    {
        return -1;
    }
    return 0;
}

Why is the check this != null here?!

Pavel Voronin
  • 13,503
  • 7
  • 71
  • 137

0 Answers0