3 ms·
This is a concern, but the advantage to Maybe is it makes this concern very explicit. SML/NJ code will not compile if you don't have a binding to handle the Non
by fixermark 11y ago
This is a concern, but the advantage to Maybe is it makes this concern very explicit. SML/NJ code will not compile if you don't have a binding to handle the None for an option 'a type.
The programmer does of course then have the option of doing
None => raise Error
but practically speaking, when deciding it's time to make your code more robust, it's a lot easier to text search for instances of "None => raise" than to search for the absence of proper handling of the possibility of a null arg or return value.
- paulddraper 11y agoExactly. You can still get errors due to things not being there. But your assumptions are explicitly stated. You see None => raise Error, and a little alarm goes off in your head, and you look around for a reassurance that we really want to do that. In contrast, you don't give x.toUpperCase() a second glance.