From: Ohad Rodeh <orodeh@cs.cornell.edu>
To: caml-list@inria.fr
Subject: Stdlib regularity
Date: Wed, 6 Oct 1999 09:25:53 -0400 (EDT) [thread overview]
Message-ID: <Pine.LNX.4.10.9910060925320.18180-100000@mojave.cs.cornell.edu> (raw)
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.
next reply other threads:[~1999-10-06 14:24 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
1999-10-06 13:25 Ohad Rodeh [this message]
1999-10-06 16:18 ` Markus Mottl
1999-10-08 14:06 ` Matías Giovannini
1999-10-10 20:09 ` Pierre Weis
1999-10-10 20:12 ` Matías Giovannini
1999-10-08 14:10 ` skaller
1999-10-08 19:21 ` Markus Mottl
1999-10-09 21:14 ` Dave Mason
1999-10-06 18:50 ` John Prevost
1999-10-07 7:33 ` skaller
1999-10-07 9:18 ` Francisco Valverde Albacete
1999-10-08 14:56 ` skaller
1999-10-09 22:26 ` Francois Rouaix
1999-10-10 5:38 ` skaller
1999-10-10 20:44 ` William Chesters
1999-10-10 21:43 ` Hongwei Xi
1999-10-11 0:36 ` skaller
1999-10-12 7:20 ` David Mentr{'e}
1999-10-08 16:38 ` Proposal for study: Add a categorical Initial type to ocaml skaller
1999-10-09 22:43 ` John Prevost
1999-10-10 3:18 ` chet
1999-10-10 6:14 ` skaller
1999-10-10 21:05 ` William Chesters
1999-10-10 22:36 ` chet
1999-10-10 22:38 ` chet
1999-10-11 19:30 ` John Prevost
1999-10-12 8:34 ` Option types and O'Labl merger Jacques Garrigue
1999-10-12 14:38 ` William Chesters
1999-10-13 5:35 ` Frank A. Christoph
1999-10-13 8:48 ` Jacques Garrigue
1999-10-11 0:51 ` Proposal for study: Add a categorical Initial type to ocaml skaller
1999-10-11 12:40 ` John Prevost
1999-10-12 19:20 ` skaller
1999-10-12 11:33 ` Jean-Francois Monin
1999-10-10 16:10 ` chet
1999-10-09 16:58 Stdlib regularity William Chesters
1999-10-10 0:11 ` Matías Giovannini
1999-10-12 16:21 Damien Doligez
1999-10-13 12:18 ` Matías Giovannini
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Pine.LNX.4.10.9910060925320.18180-100000@mojave.cs.cornell.edu \
--to=orodeh@cs.cornell.edu \
--cc=caml-list@inria.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).