On Mon, May 31, 2010 at 9:30 PM, Nicolas Pouillard <[email protected]> wrote: > > Since having all functions in all flavours can lead to hard to interface > bloat, one should consider tiny functions to switch from a style to another. > It tends to be easier to start from an option type in the case of Not_found > instead of the other way around for the following reason: > > * The typechecker does not remind us to catch the exception. > * We need a custom handler per exception. > * We need to take a thunk to delay the computation. > > let not_found_to_option f = > try Some (f ()) > with Not_found -> None > > On the contrary look at: > > let from_option exn = function > | Some x -> x > | None -> raise exn > > Example: from_option Not_found (List.find p xs) >
I use a syntax extension that catches "Not_found" and raises a failure instead, with the source location of the "real" offending call. I do this mostly because OUnit catches exceptions so backtraces are of no use. When I use the unmodified calls, I always handle Not_found right away, close to call point -- either by directly catching it, or by using a higher-order function, like an iterator that expects Not_found instead of None from the callee. Anyway, I vote for "option"ising all of the standard library and providing the function "unsome" raising a string with source code location of its call. _______________________________________________ Caml-list mailing list. Subscription management: http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list Archives: http://caml.inria.fr Beginner's list: http://groups.yahoo.com/group/ocaml_beginners Bug reports: http://caml.inria.fr/bin/caml-bugs
