types - Null Vs Option in F# -
i have problem understanding co-existence of "null" , option in f#. in book have read null value not proper value in f# because way f# eliminates excessive null checking. still allows null-initialized references in f#. in other words, can have null values don't have weapons defend with. why not replace nulls options. because of compatibility issues .net libraries or languages it's still there? if yes can give example shows why can't replaced option?
f# avoids use of null
when possible, lives in .net eco-system, cannot avoid completely. in perfect world, there no null
values, need them.
for example, may need call .net method null
argument , may need check whether result of .net method call null
.
the way f# deals is:
null used when working types come .net (when have value or argument of type declared in .net, can use
null
value of type; can test if equalsnull
)option needed when working f# types, because values of types declared in f# cannot
null
(and compiler prohibits usingnull
value of these types).in f# programming, you'll use option when working .net types (if have control on how values created). you'll never create
null
value , use option have guarantee you'll handle missing values correctly.
this option. if wanted view types options implicitly when accessing .net api, pretty every method like:
option<control> getnextchild(option<form> form, option<control> current);
...programming api quite painful.
Comments
Post a Comment