Use exceptions
Exceptions can be returned from functions without affecting the normal return type
- fun find pred nil = raise NotFound
if pred x then x else find pred xs;
val find = fn : (‘a->bool) -> ‘a list -> ‘a
- find is_positive [~3,3,5];
- find is_positive [~3,~5];
uncaught exception NotFound