caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Re: new library modules (sets and maps)
@ 1993-05-05 15:40 Didier Remy
  1993-05-06  0:37 ` Xavier Leroy
  0 siblings, 1 reply; 3+ messages in thread
From: Didier Remy @ 1993-05-05 15:40 UTC (permalink / raw)
  To: xavier; +Cc: caml-list


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.




^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~1993-05-06  8:55 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1993-05-05 15:40 new library modules (sets and maps) Didier Remy
1993-05-06  0:37 ` Xavier Leroy
1993-05-06  8:39   ` Benjamin Pierce

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).