caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: "CUOQ Pascal" <Pascal.CUOQ@cea.fr>
To: <caml-list@yquem.inria.fr>
Subject: Re: Caml-list] Sets and home-made ordered types
Date: Thu, 17 Sep 2009 08:21:40 +0200	[thread overview]
Message-ID: <5EFD4D7AC6265F4D9D3A849CEA9219191AB20D@LAXA.intra.cea.fr> (raw)
In-Reply-To: <20090917030607.927BCBCA9@yquem.inria.fr>

[-- Attachment #1: Type: text/plain, Size: 1091 bytes --]


David Allsopp wrote :
> Is it not possible to model your requirement using Map.Make instead - where
> the keys represent the equivalence classes and the values whatever data
> you're associating with them? 

Matthias Puech wrote:
>Yes, that's exactly the workaround I ended up using, although I'm not
>very happy with it because, among other things, these keys/class
>disciminant get duplicated (once inside the key, once inside the
>element). I'm getting more concrete below.

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




[-- Attachment #2: winmail.dat --]
[-- Type: application/ms-tnef, Size: 3196 bytes --]

       reply	other threads:[~2009-09-17  6:21 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20090917030607.927BCBCA9@yquem.inria.fr>
2009-09-17  6:21 ` CUOQ Pascal [this message]
2009-09-17  8:45   ` [Caml-list] " Matthias Puech
2009-09-17  9:07     ` CUOQ Pascal

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=5EFD4D7AC6265F4D9D3A849CEA9219191AB20D@LAXA.intra.cea.fr \
    --to=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).