From: remy@research.att.com (Didier Remy)
To: xavier@theory.stanford.edu
Cc: caml-list@margaux
Subject: Re: new library modules (sets and maps)
Date: Wed, 5 May 93 11:40 EDT [thread overview]
Message-ID: <m0nqlad-000CmwC@hunny.research.att.com> (raw)
Of course, the typechecker cannot tell whether you are using two different
orderings on the same map. If you pack the ordering with the primitives in a
record, you could also associate a stamp to the package (each timem you pass
a different ordering) which you be used to mark all sets created by this
package. Then you could dynamically check whether two sets sets are
originated from the same package. Except that you cannot generate stamps in
a purely applicative style!
Using an object oriented style, you could consider the functions on sets as
methods, and pack them with each set (instead of the stamp). The primitives
then take just call the right methods from the set they operate on, which
prevent from using two differnt ordering on the same set. In fact it is
enough to pack only the ordering "method".
The interface would still be:
type 'a t;;
type 'a ordering == 'a -> 'a -> int;;
type ('a, 'b) set_operations =
{ empty: 'a t;
is_empty: 'a t -> bool;
mem: 'a -> 'a t -> bool;
add: 'a -> 'a t -> 'a t;
iter: ('a -> 'b) -> 'a t -> unit;
(* and so on *) };;
value make: 'a ordering -> ('a, 'b) set_operations;;
but the implementation of 'a t is now
type 'a t = {ordering : 'a -> 'a -> 'int;
val : 'a old_t};;
and the implementation of the functions would changed accordingly to take
the ordering from their argument rather than from their closure. Of course,
there is an ambiguity for functions working on several sets. The functions
could be written to work with two orderings, one for each set, but this may
complicate their implementation or slower their execution, for a situation
that should not arise in practice...
Didier.
next reply other threads:[~1993-05-05 15:43 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
1993-05-05 15:40 Didier Remy [this message]
1993-05-06 0:37 ` Xavier Leroy
1993-05-06 8:39 ` Benjamin Pierce
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=m0nqlad-000CmwC@hunny.research.att.com \
--to=remy@research.att.com \
--cc=caml-list@margaux \
--cc=xavier@theory.stanford.edu \
/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