On Tue, Nov 07, 2017 at 03:16:31PM +0100, Pino Toscano wrote: > On Sunday, 8 October 2017 23:26:53 CET Richard W.M. Jones wrote: > > We defined a number of functions on lists which are not provided by > > the standard library. As with Char and String, let's extend List to > > add these new functions to a List pseudo-module (really > > Std_utils.List, but called List when you ‘open Std_utils’). > > > > The initial exported functions are all List functions from OCaml 3.11 > > + iteri + mapi. We can add other functions as needed. > > --- > > My worry about this is that: > - OCaml does not have OOTB support for conditional code depending on the > version > - the interface of the List module would get "frozen" this way, and > overrides the module in the standard library > then we could run into issues like commit > 7cd27531154dd25d9093cf04c085a3669bc834e5, i.e. restricting the interface > because of compatibility issues.
This commit stopped a symbol from being exported which didn't exist in whatever minimum version of OCaml we were supporting at the time (3.11 I think). It didn't restrict what we could do: * If we wanted to stay with [whatever minimum version of OCaml] then we would have had to reimplement ‘StringSet.map’. * It didn't stop us from reimplementing ‘StringSet.map’ if we had needed it. * We could move to a new minimum version of OCaml and add newer functions to Char, String and List. > Also IMHO this makes more difficult to know what's stdlib and what's > ours, when using the API -- I guess I mentioned that when String was > introduced, maybe... Plainly it is true that from just reading the code you can't easily tell that ‘List.map’ is really ‘Std_utils.List.map’. (In emacs you can use ‘M-x caml-types-show-ident’ to show the true name.) But I think it's good that we can add new functions under the Char, String and List modules. It's also a fairly common technique. Most notably it was used by ExtLib[1] for the last 14 years. Rich. [1] https://github.com/ygrek/ocaml-extlib/blob/41951de2ce604c6fc0bf72a86f77d67c7a40ad30/src/extList.mli#L31 -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-df lists disk usage of guests without needing to install any software inside the virtual machine. Supports Linux and Windows. http://people.redhat.com/~rjones/virt-df/ _______________________________________________ Libguestfs mailing list [email protected] https://www.redhat.com/mailman/listinfo/libguestfs
