caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: "Jean-Christophe Filliâtre" <Jean-Christophe.Filliatre@lri.fr>
To: Fabrice Marchant <fabricemarchant@free.fr>
Cc: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] Building a Set module for elements of a Map
Date: Thu, 26 Jun 2008 11:21:09 +0200	[thread overview]
Message-ID: <48635F85.4030108@lri.fr> (raw)
In-Reply-To: <20080625153043.3bd7895c@free.fr>

Fabrice Marchant wrote:

> Please consider a functor F that takes as input the output signature of a Map.
> 
> Here is the only way I see to declare a Set module whose elements type are Map.S.key :
> 
> module F ( M : Map.S ) = struct  
>   module MKeySet =
>     Set.Make ( struct type t = M.key let compare = compare end )
> end
> 
>   The problem is to access the OrderedType that permitted to build the Map M. It seems to have disappeared inside the output Map signature S. So the trial of regeneration :
> struct type t = M.key let compare = compare end
> 
>   It maybe exists a straightforward signature we could pick somewhere inside Map related modules ?
>   Moreover I'm afraid this "Ersatz" of signature based on _Pervasives_.compare is in some cases deficient, because different from original OrderedType of Map elements...

Using Pervasives.compare instead of a user-defined comparison function
may even be incorrect. (Suppose the intended comparison function should
identify (x,y) and (y,x), for instance; obviously, Pervasives.compare
will not.)

A possible solution to your problem is to have functor F taking instead
a module for keys as argument, and then to build module M inside F; thus
it would look like:

	module F(K : OrderedType) = struct
	  module M = Map.Make(K)
	  module MKeySet = Set.Make(K)
	  ...
	end

Hope this helps,
-- 
Jean-Christophe Filliâtre
http://www.lri.fr/~filliatr/



  reply	other threads:[~2008-06-26  9:19 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-06-25 13:30 Fabrice Marchant
2008-06-26  9:21 ` Jean-Christophe Filliâtre [this message]
2008-06-26  9:26 ` [Caml-list] " Xavier Leroy
2008-06-27 18:10 ` Fabrice Marchant

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=48635F85.4030108@lri.fr \
    --to=jean-christophe.filliatre@lri.fr \
    --cc=caml-list@yquem.inria.fr \
    --cc=fabricemarchant@free.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).