Null values for F# classes

The next problem I found in my efforts to make XPO work with F# is documented here: Null values for F# classes – basically, I can’t just set a variable that has a reference to another object to null in F#.

The general assumption in F# is that null values are a threat and so the languages discourages their use. I totally see the point and if all I wanted to do was create classes (or perhaps not even those) for use in F# itself, I wouldn’t have a problem with it – but interop is an important thing for F#, as I see it, and all the rest of the .NET world makes elaborate use of null values. Null values are the (rather more dangerous) alternative to F# Options to most .NET developers – exactly the same purpose, just a less elegant implementation.

I haven’t given up on the Hub yet, although I have to say I haven’t received any useful replies from there yet… and the people who do reply are rather those that like to write forum posts than those who really know what they’re talking about 😉 Anyway, perhaps I’ll get lucky with a blog post again – Brian, are you still reading? 😉

UPDATE: I found the solution to this problem in the release notes for F# 1.9.4: use the Unchecked.defaultof<T> function. I guess that’s the new functionality that was referred to earlier. Great!

Leave a Comment

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s