From: Nicolas C. <war...@fr...> - 2003-02-27 03:07:14
|
Hi, I've read all the comments about MutableList modules, and several importa= nt points have been raised. Thanks to all people who have replied ! - yes, MList was intended as a additionnal module - of course, for end users, a fully documented module will be released - in the documentation, we can put some note about implementation, saying that MList.t =3D list ref ( this clarify most of the questions ) - yes using labels for "copy" make sense - map_list : ('a -> 'b) -> 'a t -> 'b list is approved - shuffle simply do shuffle the list in-place. ( that's a random sort, so= it is O(n=B2) ) About Complexity, I think this has of course be part of the documentation= : - copy and copy-list are O(1) - length is O(n) - set and remove_at_index are O(n) About Exceptions, let me disagree with the current standard library model= . Of couse, for many functions not-so-much-used a Failure "msg" is a very g= ood way of raising an exception. But when you're using data structures such a= s lists, catching an exception is a very common way of handling different cases, so exception cannot be seen anymore as an error message, but as a possible kind of return value, so has to have a named constructor. most of the time when using the stdlib I end up using pattern matching to catch only one kind of failure : try let h =3D List.hd l in < do something with it > with Failure "hd" -> < handle it > Imagine that List.find would raise Failure "find" instead of Not_found... That wouldn't be nice... Why ? because we catch Not_found many times, tha= t's why a separate constructor has been created. I don't really interstand caml-team Failure usage in the stdlib because it's so "old-style" and "weakly-typed" ( you can for example make a syntax error in the error message... ). For me, Failure exceptions are the one which are designed t= o be raised up to the toplevel... and printed. When you have an exception which is worth catching, you have to define a constructor. And several constructors are making your code much easier to debug. Nicolas Cannasse |