Another way to get the behavior of the described Maybe method is to enforce a coding style where functions require a default return value to be passed in - this lets it be handled in a precise manner and surfaces most problems quickly, without butchering fundamental assumptions of the language.
The real difficulty comes in when you want to enforce a branch for functions that are "rarely null" instead of having them blow up much later when you inevitably forget to handle the null case. A lot of the time the only immediate way to avoid this class of error is to use algorithms that will never stumble over a null(which tends to make them a lot slower) - if you have macros or richer type systems, other things are possible of course.
obj.nil? # => true
!!obj # => trueYou can override ! (see http://www.rubyinside.com/rubys-unary-operators-and-how-to-r... from earlier this week) so !!obj can evaluate to false. But there is still this to solve:
ruby-1.9.3-p0 :008 > obj ? true : false
=> true
ruby-1.9.3-p0 :009 >
If only there was a #to_bool to override...(For the record: yuck).
I'd also like just letting nils be nils :) but good presentation.
a) Integrating with other codebases that don't use Maybe will result in code with an inconsistent style, and
b) If Maybe (or something like it) catches on enough, you'll hit collisions where two projects or libraries have different ideas of what Maybe means. (Maybe one uses NilClass, the other the custom NullClass, for example.)
(The PHP community has taken this to the extreme, with developers getting burnt over and over again with differing "standard" components using the same set of names.)