From: Jacques Garrigue <garrigue@kurims.kyoto-u.ac.jp>
To: yann.coscoy@icdc.caissedesdepots.fr
Cc: caml-list@inria.fr
Subject: Re: hashtables for mutable records
Date: Fri, 28 Apr 2000 10:12:27 +0900 [thread overview]
Message-ID: <20000428101227D.garrigue@kurims.kyoto-u.ac.jp> (raw)
In-Reply-To: Your message of "Thu, 27 Apr 2000 15:28:41 +0200" <40C4228EC468D211B04800A0C9DF1D6636DE0C@tsexchange.idt.cdc.fr>
From: "Coscoy, Yann" <yann.coscoy@icdc.caissedesdepots.fr>
> I want to do an hashtable on mutable and polymorphic records. Standard
> module Hashtbl is not suitable because:
> - Hashtbl.HashType doesn't accept polymorphic types.
> - Hashtbl.hash is susceptible to setups of a mutable fields.
The standard functorial solution would be to define a new functor:
type 'a polyref = {mutable data: 'a; id: int}
module PolyHash(T : sig type t end) =
Hashtbl.Make
(struct
type t = T.t polyref
let equal a b = (a.id = b.id)
let hash a = a.id
end)
module IntHash = PolyHash(struct type t = int end)
module BoolHash = PolyHash(struct type t = bool end)
The only dificulty with such an approach is that you must use
different functions for different hashtables.
If you want to define new polymorphic functions using these
hashtables, you must again put them in a functor.
Regards,
Jacques
---------------------------------------------------------------------------
Jacques Garrigue Kyoto University garrigue at kurims.kyoto-u.ac.jp
<A HREF=http://wwwfun.kurims.kyoto-u.ac.jp/~garrigue/>JG</A>
next prev parent reply other threads:[~2000-04-28 10:07 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2000-04-27 13:28 Coscoy, Yann
2000-04-27 17:56 ` Pierre Weis
2000-04-28 1:12 ` Jacques Garrigue [this message]
2000-04-28 8:14 Coscoy, Yann
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=20000428101227D.garrigue@kurims.kyoto-u.ac.jp \
--to=garrigue@kurims.kyoto-u.ac.jp \
--cc=caml-list@inria.fr \
--cc=yann.coscoy@icdc.caissedesdepots.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