caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Matthias Puech <puech@cs.unibo.it>
To: CUOQ Pascal <Pascal.CUOQ@cea.fr>
Cc: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] Sets and home-made ordered types
Date: Thu, 17 Sep 2009 10:45:52 +0200	[thread overview]
Message-ID: <4AB1F740.9020404@cs.unibo.it> (raw)
In-Reply-To: <5EFD4D7AC6265F4D9D3A849CEA9219191AB20D@LAXA.intra.cea.fr>

Hello and thanks to all for your answers,

If I understand correctly, you're all (David, Elnatan, Vincent, 
Tiphaine, Pascal) suggesting more or less the same solution (the one 
below). Do you have an idea of its memory overhead compared to just 
using Sets? I guess the value is not copied twice but shared between 
keys and elements right? So what, one pointer more for each association 
in the Map? That would be rather acceptable (but still not ideal, sorry 
I'm very demanding).

Thanks again,

    -- Matthias

CUOQ Pascal a écrit :
> Since you already have the "compare" function between objects of
> type t, why don't you make your map associate values of type t to
> identical values of type t instead of trying to have different type
> for keys and elements?
>
> You can even do it generically, and obtain with little effort an
> implementation of sets that supports find.
>
> module Set_With_Find(X:Set.OrderedType) = 
> struct
>       module M = Map.Make(X)
>       type t = X.t M.t (* with invariant that value v is always associated to v *)
>       let find = M.find
>       let add v s = M.add v v s
>       .......
> end
>
> Pascal
>
>
>
>   
> ------------------------------------------------------------------------
>
> _______________________________________________
> Caml-list mailing list. Subscription management:
> http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
> Archives: http://caml.inria.fr
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs
>   


  reply	other threads:[~2009-09-17  8:47 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20090917030607.927BCBCA9@yquem.inria.fr>
2009-09-17  6:21 ` Caml-list] " CUOQ Pascal
2009-09-17  8:45   ` Matthias Puech [this message]
2009-09-17  9:07     ` CUOQ Pascal
2009-09-16 16:40 Matthias Puech
     [not found] ` <002e01ca36fd$37656c60$a6304520$@metastack.com>
2009-09-16 21:38   ` [Caml-list] " Matthias Puech
2009-09-17  7:31     ` Vincent Aravantinos
2009-09-17  8:39     ` David Allsopp
2009-09-23 10:46     ` Goswin von Brederlow

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=4AB1F740.9020404@cs.unibo.it \
    --to=puech@cs.unibo.it \
    --cc=Pascal.CUOQ@cea.fr \
    --cc=caml-list@yquem.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).