In his message of Tue March 7, 2000, Markus Mottl writes:
> it sometimes happens that I need functions on abstract data types in the
> standard library which are not available there, but could be considered as
> "usual" operations on such data. Also some other very commonly useful
> functions could be added.
I agree.
One may think that the functions you suggest can actually be defined
outside the standard library using iterators like fold (not for
Stack.top, however). For instance, one can define set_exists as
======================================================================
# module Myset = Set.Make(struct type t = ... let compare = ... end);;
...
# let set_exists p s =
try Myset.fold (fun x _ -> if p x then failwith "t") s (); false
with Failure "t" -> true;;
val set_exists : (Myset.elt -> bool) -> Myset.t -> bool = <fun>
======================================================================
But when using functorial interfaces like Set.Make, you have to
redefine these functions for each application of the functor. Thus,
you really need these functions to be defined in the functor i.e.
together with the datatype (and, by the way, you can then define these
functions a bit more efficiently---without using exceptions).
-- Jean-Christophe Filliatre Computer Science Laboratory Phone (650) 859-5173 SRI International FAX (650) 859-2844 333 Ravenswood Ave. email filliatr@csl.sri.com Menlo Park, CA 94025, USA web http://www.csl.sri.com/~filliatr
This archive was generated by hypermail 2b29 : Fri Mar 10 2000 - 09:04:00 MET