From: Nicolas C. <war...@fr...> - 2004-04-28 18:12:26
|
> hi list, > i find myself often having to do [1] > > if Hashtbl.mem h k then > let v = Hashtbl.find h k in ... do stg with k here [...] > [1] And of course i could simply wrap Hashtbl.find and catch Not_found, > but this is performance sensitive, and i have some vague recollection of > there being a cost to putting stuff in a try.. with block. Exceptions in OCaml are very cheap (unlike Java for example) and very useful to propagate some state. For instance, doing and Hashtbl.mem + an Hashtbl.find looks more costly than wrapping the "find" into a try..with block. But whatever the performances, I think it can be useful to have : val find_option : ('a,'b) Hashtbl.t -> 'a -> 'b option (not that it's not default, since a default is returning a default value, with same type). I'll add this to the ExtLib CVS. Regards, Nicolas Cannasse |