caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Philippe Wang <lists@philippewang.info>
To: skaller <skaller@users.sourceforge.net>
Cc: tmp123@menta.net, ocaml ml <caml-list@inria.fr>
Subject: Re: [Caml-list] Sorted list
Date: Sat, 04 Aug 2007 14:23:15 +0200	[thread overview]
Message-ID: <46B46FB3.3090606@philippewang.info> (raw)
In-Reply-To: <1186226538.14440.105.camel@rosella.wigram>

skaller wrote:
> On Sat, 2007-08-04 at 12:29 +0200, Philippe Wang wrote:
>   
>> tmp123@menta.net wrote:
>>     
>
>   
>>> Of the standard modules, the most similar seems "set", because allows 
>>> insertion and has the funcion "min_elt". However, the problem is, if 
>>> two timers have the same time, addition of the second one removes the 
>>> first.
>>>
>>> Please, has someone any sugestion?
>>>
>>> Thanks a lot.
>>>       
>> Hello,
>>
>> Let's remind that Set.Make is a functor that takes a module with
>> sig
>>   type t
>>   val compare : t -> t -> int
>> end
>>
>> If you simply give him a compare function that never returns 0, then you 
>> can add multiple elements that are the same.
>>     
>
> You cannot do that! compare function must be a total order.
>   
Why not ?



        Objective Caml version 3.10.0

# include Set.Make(struct type t = int let compare : t -> t -> int = fun 
a b -> match compare a b with 0 -> 1 | n -> n end);;
type elt = int
type t
val empty : t = <abstr>
val is_empty : t -> bool = <fun>
val mem : elt -> t -> bool = <fun>
val add : elt -> t -> t = <fun>
val singleton : elt -> t = <fun>
val remove : elt -> t -> t = <fun>
val union : t -> t -> t = <fun>
val inter : t -> t -> t = <fun>
val diff : t -> t -> t = <fun>
val compare : t -> t -> int = <fun>
val equal : t -> t -> bool = <fun>
val subset : t -> t -> bool = <fun>
val iter : (elt -> unit) -> t -> unit = <fun>
val fold : (elt -> 'a -> 'a) -> t -> 'a -> 'a = <fun>
val for_all : (elt -> bool) -> t -> bool = <fun>
val exists : (elt -> bool) -> t -> bool = <fun>
val filter : (elt -> bool) -> t -> t = <fun>
val partition : (elt -> bool) -> t -> t * t = <fun>
val cardinal : t -> int = <fun>
val elements : t -> elt list = <fun>
val min_elt : t -> elt = <fun>
val max_elt : t -> elt = <fun>
val choose : t -> elt = <fun>
val split : elt -> t -> t * bool * t = <fun>

# let x = empty ;;
val x : t = <abstr>
# let x = add 1 x ;;
val x : t = <abstr>
# let x = add 1 x ;;
val x : t = <abstr>
# let x = add 1 x ;;
val x : t = <abstr>
# let x = add 42 x ;;
val x : t = <abstr>
# let x = add 45 x ;;
val x : t = <abstr>
# elements x ;;
- : elt list = [1; 1; 1; 42; 45]

It works ! ... Or did I miss something ?


  reply	other threads:[~2007-08-04 12:23 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-08-04  9:35 tmp123
2007-08-04 10:00 ` [Caml-list] " Jon Harrop
2007-08-04 10:29 ` Philippe Wang
2007-08-04 11:22   ` skaller
2007-08-04 12:23     ` Philippe Wang [this message]
2007-08-04 13:39       ` skaller
2007-08-04 14:01         ` Philippe Wang
2007-08-04 14:45           ` skaller
2007-08-04 14:27       ` tmp123
2007-08-04 20:33       ` Christophe TROESTLER
2007-08-04 14:37     ` tmp123
2007-08-04 15:09       ` Brian Hurt
2007-08-04 15:42         ` skaller
2007-08-04 16:21           ` Richard Jones
2007-08-04 17:17             ` Brian Hurt
2007-08-04 18:24               ` skaller
2007-08-04 17:54             ` skaller
2007-08-04 19:16               ` Richard Jones
2007-08-05 16:22                 ` David Allsopp
2007-08-05 16:41                   ` Xavier Leroy
2007-08-05 17:01                     ` David Allsopp
2007-08-04 17:35           ` Julien Moutinho
2007-08-04 18:04             ` skaller
2007-08-05  1:47             ` Jon Harrop
2007-08-05 11:44               ` Erik de Castro Lopo
2007-08-05 12:03                 ` Jacques GARRIGUE
2007-08-05 12:31                   ` Erik de Castro Lopo
2007-08-05 13:22                     ` Richard Jones
2007-08-05 20:47                       ` Erik de Castro Lopo
2007-08-05 13:17                 ` Richard Jones
2007-08-05 16:26           ` Xavier Leroy
2007-08-05 23:47             ` skaller
2007-08-04 15:36       ` skaller
2007-08-04 15:17     ` tmp123
2007-08-12 12:05       ` Andrej Bauer
2007-08-04 12:15 ` Brian Hurt
2007-08-04 12:36   ` Brian Hurt
2007-08-04 13:49     ` skaller
2007-08-04 12:16 ` Daniel Bünzli
2007-08-04 12:58 ` Oliver Bandel

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=46B46FB3.3090606@philippewang.info \
    --to=lists@philippewang.info \
    --cc=caml-list@inria.fr \
    --cc=skaller@users.sourceforge.net \
    --cc=tmp123@menta.net \
    /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).