More F# neat features
-
Option types[^] In ideal world that would eliminate the use of
Null
(which was a billion dollar mistake[^] as admitted by its inventor Tony Hoare). Unfortunatelly, the world is not ideal, and when you use types from .NET framework,Null
still needs to be taken into account[^]. Backwards compatibility at its best :)My language works better:-
NSString* x = nil;
[x upperCaseString]; // Never crashes
Yes in Objective C it is OK to call methods (send messages) to nil object(s). ;P
-
Joe Woodbury wrote:
You still HAVE to know if a return value can be None.
The return type tells me if a return value can be None.
string s = find_string(); // compile error - the return type is option, not string
-
Option types[^] In ideal world that would eliminate the use of
Null
(which was a billion dollar mistake[^] as admitted by its inventor Tony Hoare). Unfortunatelly, the world is not ideal, and when you use types from .NET framework,Null
still needs to be taken into account[^]. Backwards compatibility at its best :)Also a C++ feature if you use Boost[^] :-) I prefer the Haskell implementation[^], though - mainly because (unlike F# and OCaml) it's not a special case builtin type, although it feels like one, because it can utilise Haskell's type classes to fit in liek a builtin type.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
-
so instead of looking up the return values for a function that returns a pointer, which could be null & which you should check, you state that it would be better to do what exactly?
bulg wrote:
so instead of looking up the return values for a function that returns a pointer, which could be null & which you should check, you state that it would be better to do what exactly?
Declare the function to return an option type and then if you try to assign the return value directly to a pointer without checking for null, you get a compile error.
-
Would introducing a
Maybe<T>
struct into the framework accomplish the same thing? Obviously, there would have to be widespread support throughout the APIs, and tons of things would break, but I'm just thinking aloud here.Religiously blogging on the intarwebs since the early 21st century: Kineti L'Tziyon Judah Himango
That would violate basic principles of Boolean logic, developed by George Boole, in which everything either is or isn't. Fortunately his wife, Mary, extended his work to incorporate a third state in logic, "maybe" (some texts refer to this value as "that depends"). I say 'fortunately' because, without this logical extension, it would have been impossible for women to become programmers. Limiting them to simple choices between "true" and "false" is cruel, and ultimately crippling. Programming would have been consigned to pale, nervous, socially backward, and very lonely men if George had got the final word. But what were the odds of that happenning?
"A Journey of a Thousand Rest Stops Begins with a Single Movement"
-
My language works better:-
NSString* x = nil;
[x upperCaseString]; // Never crashes
Yes in Objective C it is OK to call methods (send messages) to nil object(s). ;P
Heh, interesting. Do you also send messages to ask for data, e.g. var result = Foo.Bar? What happens when you ask for a result from a nil object?
Religiously blogging on the intarwebs since the early 21st century: Kineti L'Tziyon Judah Himango
-
Would introducing a
Maybe<T>
struct into the framework accomplish the same thing? Obviously, there would have to be widespread support throughout the APIs, and tons of things would break, but I'm just thinking aloud here.Religiously blogging on the intarwebs since the early 21st century: Kineti L'Tziyon Judah Himango
it's called Nullable<T> which itself is a value type and therefore cannot be null.
-
That would violate basic principles of Boolean logic, developed by George Boole, in which everything either is or isn't. Fortunately his wife, Mary, extended his work to incorporate a third state in logic, "maybe" (some texts refer to this value as "that depends"). I say 'fortunately' because, without this logical extension, it would have been impossible for women to become programmers. Limiting them to simple choices between "true" and "false" is cruel, and ultimately crippling. Programming would have been consigned to pale, nervous, socially backward, and very lonely men if George had got the final word. But what were the odds of that happenning?
"A Journey of a Thousand Rest Stops Begins with a Single Movement"
Roger Wright wrote:
But what were the odds of that happenning?
one would say 50%, given the possible boolean logic results. obviously it was 0%.
-
it's called Nullable<T> which itself is a value type and therefore cannot be null.
Doesn't work for this situation.
Nullable<T>
only works with value types; the only reason we'd introduceMaybe<T>
is for reference types.Religiously blogging on the intarwebs since the early 21st century: Kineti L'Tziyon Judah Himango
-
Roger Wright wrote:
But what were the odds of that happenning?
one would say 50%, given the possible boolean logic results. obviously it was 0%.
That depends... ;P
"A Journey of a Thousand Rest Stops Begins with a Single Movement"