In F# mantra there seems to be a visceral avoidance of null
, Nullable<T>
and its ilk. In exchange, we are supposed to instead use option types. To be honest, I don't really see the difference.
My understanding of the F# option type is that it allows you to specify a type which can contain any of its normal values, or
None
. For example, anOption<int>
allows all of the values that anint
can have, in addition toNone
.My understanding of the C# nullable types is that it allows you to specify a type which can contain any of its normal values, or
null
. For example, aNullable<int>
a.k.aint?
allows all of the values that anint
can have, in addition tonull
.
What's the difference? Do some vocabulary replacement with Nullable
and Option
, null
and None
, and you basically have the same thing. What's all the fuss over null
about?