4 ms·
Pardon my confusion, but is null referring to that of Java-style reference types, in which case the article is really about those? The value itself seems irrele
by pubby 14y ago
Pardon my confusion, but is null referring to that of Java-style reference types, in which case the article is really about those? The value itself seems irrelevant as null is practically equivalent to Nothing. Now, if comparing the types then I'd say that Haskell's Maybe has the following improvements over Java-style optional:
1. Opt-in
2. Not tied to reference types
3. Safe extraction/"dereferencing". ie case expressions rather than Java's implicit "Maybe t -> t"
All of which aren't restricted to a static type system.
- acomar 14y agoYep, you've got it exactly right. The problem for dynamic type systems is how do you enforce 3? Do you care to?
- geon 14y agoI suppose you could write a sort of safe Maybe template class in c++. You could pass in two callbacks to handle Just and Nothing respectively. It would be really ugly, but should work, right?
- pubby 14y agoYeah, a function taking two callbacks is what I had in mind. This works in dynamic typed languages too, although obviously not as well.