We were unable to load Disqus. If you are a moderator please see our troubleshooting guide.

Mark Needham • 16 years ago

@Alex I think if it's just single values that we care about (as in my example) then the main benefit for me is that you're explicitly saying that the value might have a value but it might not - I guess maybe this is the same as with the nullable type in C#.

If you're doing something like iterating over a list which has Options in it then your ability to do pattern matching is much improved since you can easily distinguish between whether you are dealing with something which has a value and something which doesn't. It wouldn't be so easy if you had to distinguish between null and not null from what I understand.

Alex O. • 16 years ago

I am new to F# and like what I see so far.
But I'd like to voice some dissent on this issue though: while the Option type helps to avoid the exception in this case, it still requires the use of a dedicated try... function, so in the end it's still the programmer's responsibility to account for a possible nullable result of an operation. In other words, this safer result handling does not come "for free" from the language.
So, my question: how is it fundamentally better than, say, nullable types in C# or similar functions in .NET in general (e.g. Int32.TryParse())?

Just trying to learn, that's all.

Robert Pickering • 17 years ago

I've been a big fan of using the option type instead of null for quite a while now. To me although it's just a small change, it really does lead to cleaner, safer code. I talk some more about how it can be used in this blog post:
http://strangelights.com/bl...