It's pretty easy to switch back and forth between representing a function with a "maybe" result type as:
- returning X or #f;
- returning X or raising an exception; or
- returning X and taking a failure thunk
In Scheme, sometimes X might include the value
#f. In that case I think representation #3 is the best one, since raising an exception is clunky. You can also combine #2 and #3 and take an optional thunk that by default raises an exception.
This is one case where
true unions do cause some problems, so maybe I should have tempered my earlier enthusiasm a little. Still, it's not insurmountable, and this cost needs to be weighed against
the price of strictly disjoint unions.