From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id QAA00251 for caml-redistribution; Wed, 6 Oct 1999 16:24:54 +0200 (MET DST) Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id PAA30183 for ; Wed, 6 Oct 1999 15:26:07 +0200 (MET DST) Received: from simon.cs.cornell.edu (SIMON.CS.CORNELL.EDU [128.84.154.10]) by nez-perce.inria.fr (8.8.7/8.8.7) with ESMTP id PAA07265 for ; Wed, 6 Oct 1999 15:26:03 +0200 (MET DST) Received: from cloyd.cs.cornell.edu (CLOYD.CS.CORNELL.EDU [128.84.227.15]) by simon.cs.cornell.edu (8.9.3/8.9.3/R-2.5) with ESMTP id JAA23820 for ; Wed, 6 Oct 1999 09:26:01 -0400 (EDT) Received: from mojave.cs.cornell.edu (IDENT:orodeh@MOJAVE.CS.CORNELL.EDU [128.84.248.55]) by cloyd.cs.cornell.edu (8.9.3/8.9.3/M-2.4) with ESMTP id JAA17034 for ; Wed, 6 Oct 1999 09:25:55 -0400 (EDT) Received: from localhost (orodeh@localhost) by mojave.cs.cornell.edu (8.8.7/8.8.8/LX-1.2) with ESMTP id JAA21786 for ; Wed, 6 Oct 1999 09:25:53 -0400 Date: Wed, 6 Oct 1999 09:25:53 -0400 (EDT) From: Ohad Rodeh To: caml-list@inria.fr Subject: Stdlib regularity Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: weis Caml list, I have used OCaml extensively in the past few years, and I've had some misgivings about the CAML standard library argument ordering. It is a little bit confusing and not standard. For example: val Queue.add: 'a -> 'a t -> unit val Hashtbl.add: ('a,'b) t -> 'a -> 'b -> unit My general suggestion is to always make the first argument the <'a t> type and the second the <'a> type. The only exception to this rule should be functionals, for example, in Queue: val iter: ('a -> unit) -> 'a t -> unit I've summed up the proposed changes in an order of importance, please remember that this is suggestion based on my personal taste alone. The changes I'm most interested are: Module Queue: switch: val add: 'a -> 'a t -> unit to: val add: 'a t -> 'a -> unit Module Stack: switch: val push: 'a -> 'a t -> unit to: val push: 'a t -> 'a -> unit Module Stream: switch: npeek : int -> 'a t -> 'a list;; to: npeek : 'a t -> int -> 'a list;; This make the data-structure modules (Hashtbl,Queue,Stack,Stream) behave the same. If this is possible, I'd like this to apply to the Map and Set modules. For module Map, this is the current signature: module type OrderedType = sig type t val compare: t -> t -> int end module type S = sig type key type 'a t val empty: 'a t val add: key -> 'a -> 'a t -> 'a t val find: key -> 'a t -> 'a val remove: key -> 'a t -> 'a t val mem: key -> 'a t -> bool val iter: (key -> 'a -> unit) -> 'a t -> unit val map: ('a -> 'b) -> 'a t -> 'b t val fold: (key -> 'a -> 'b -> 'b) -> 'a t -> 'b -> 'b end end module Make(Ord: OrderedType): (S with type key = Ord.t) I'd rather make it: module type S = sig type key type 'a t val empty: 'a t val add: 'a t -> key -> 'a -> 'a t val find: 'a t -> key -> 'a val remove: 'a t -> key -> 'a t val mem: 'a t -> key -> bool val iter: (key -> 'a -> unit) -> 'a t -> unit val map: ('a -> 'b) -> 'a t -> 'b t val fold: (key -> 'a -> 'b -> 'b) -> 'a t -> 'b -> 'b end For module Set, this is the current signature: module type OrderedType = sig type t val compare: t -> t -> int end module type S = sig type elt type t val empty: t val is_empty: t -> bool val mem: elt -> t -> bool val add: elt -> t -> t val singleton: elt -> t val remove: elt -> t -> t val union: t -> t -> t val inter: t -> t -> t val diff: t -> t -> t val compare: t -> t -> int val equal: t -> t -> bool val subset: t -> t -> bool val iter: (elt -> unit) -> t -> unit val fold: (elt -> 'a -> 'a) -> t -> 'a -> 'a val cardinal: t -> int val elements: t -> elt list val min_elt: t -> elt val max_elt: t -> elt val choose: t -> elt end module Make(Ord: OrderedType): (S with type elt = Ord.t) Id rather switch S to: module type S = sig type elt type t val empty: t val is_empty: t -> bool val mem: t -> elt -> bool val add: t -> elt -> t val singleton: elt -> t val remove: t -> elt -> t val union: t -> t -> t val inter: t -> t -> t val diff: t -> t -> t val compare: t -> t -> int val equal: t -> t -> bool val subset: t -> t -> bool val iter: (elt -> unit) -> t -> unit val fold: (elt -> 'a -> 'a) -> t -> 'a -> 'a val cardinal: t -> int val elements: t -> elt list val min_elt: t -> elt val max_elt: t -> elt val choose: t -> elt end Module List has some of the same functions (mem,remove), so my suggestion is: switch: val mem : 'a -> 'a list -> bool val memq : 'a -> 'a list -> bool to: val mem : 'a list -> 'a -> bool val memq : 'a list -> 'a -> bool switch: val assoc : 'a -> ('a * 'b) list -> 'b val assq : 'a -> ('a * 'b) list -> 'b val mem_assoc : 'a -> ('a * 'b) list -> bool val mem_assq : 'a -> ('a * 'b) list -> bool val remove_assoc : 'a -> ('a * 'b) list -> ('a * 'b) list val remove_assq : 'a -> ('a * 'b) list -> ('a * 'b) list to: val assoc : ('a * 'b) list -> 'a -> 'b val assq : ('a * 'b) list -> 'a-> 'b val mem_assoc : ('a * 'b) list -> 'a -> bool val mem_assq : ('a * 'b) list -> 'a-> bool val remove_assoc : ('a * 'b) list -> 'a -> ('a * 'b) list val remove_assq : ('a * 'b) list -> 'a -> ('a * 'b) list The more important changes are the first minor 3, the rest are optional. What do you think? Ohad.