F# has two kinds of data types – “classes” and “types”. Types are bags of bits, similar to C structs, only immutable (that’s C, without sharp). Classes are classes in a normal object-oriented sense.
F# types cannot be
null. Values that may or may not be present are expressed via special type
'a option. So,
int option means optional integer, conceptually very similar to
int option can take values
In Ocaml classes are also not nullable. F# needed to be compatible with .NET libraries, so it introduced
null keyword, but only for classes. F# classes are both nullable and optionable.
null is not the same as
int option are different data types.
Confused? I bet you are. And I have one more thing up my sleeve: .NET structs. This is a nut that F# authors did not crack yet.
F# types are .NET structs are both not-nullable, but they are not the same thing. F# types can’t have methods, .NET structs can. F# types don’t derive from
object, .NET structs do. Et cetera, et cetera.
Nullable<T> is conceptually similar to
T option, these are two different, incompatible things.
The bottom line is, checking something for
null in F# is very not obvious.