What should IEquatable
do when this == null
and obj == null
?
1) This code is generated
leppie is right. Just to elaborate on his answer (and confirm his suspicion that F# doesn't guarantee this != null)
: discriminated unions may be marked with the attribute [
allowing cases to be represented by the value null. Option<'T> is such a type. The None
case is represented by null at run-time. (None : option
is syntactically valid. Here's a fun example:
[]
type Maybe<'T> =
| Just of 'T
| Nothing
[]
member this.ThisIsNull() = match this with Nothing -> true | _ -> false
Decompiling ThisIsNull
with Reflector shows
public bool ThisIsNull()
{
return (this == null);
}
And the result:
Nothing.ThisIsNull() //true