From: Don Syme <dsyme@microsoft.com>
To: caml-list@inria.fr
Subject: RE: parametric types in simple functors?
Date: Fri, 9 Jul 1999 05:50:25 -0700 [thread overview]
Message-ID: <39ADCF833E74D111A2D700805F1951EF0F00BCB6@RED-MSG-06> (raw)
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 2477 bytes --]
Yes, I had the same problem just yesterday when wanting to generate the
natural, parametric version of "Map" using Pervasives.compare. In the end I
just copied to code in stdlib.map, substituting "Pervasives" for "Ord". Is
there some trick we're overlooking?
Don
-----Original Message-----
From: STARYNKEVITCH Basile [mailto:Basile.Starynkevitch@cea.fr]
Sent: 05 July 1999 11:57
To: caml-list@inria.fr
Subject: Q: parametric types in simple functors?
The subject title is poor. I have a concrete simple question.
(All CAML code is indented to the right here)
Consider
type 'a symbol = { sy_name: string; sy_hash: int; mutable sy_prop: 'a
option };;
This is essentially a symbol, memoizing its hash code for fast
access. Some structures are naturally hashed map, whose key are
symbols (eg bindings). We make symbols with
let get_symbol n =
try Hashtbl.find symdict n
with Not_found ->
let s = { sy_name=n; sy_hash=Hashtbl.hash n; sy_prop=None } in
Hashtbl.add symdict n s;
s
;;
The property field of symbols could be used the way you like it.
I want to define a binding as an hashtable mapping symbols to (say)
integers - or even any type 'b. But I can't code:
module SymbolHash = Hashtbl.Make(
struct
type t = symbol
let equal s1 s2 = s1 == s2
let hash {sy_hash=h} = h
end)
;;
Because the type constructor t has no argument in the
Hashtbl.HashedType signature.
Any comments or suggestions (could define a class abstract_symbol
with a subclass symbol holding the properties. But I don't want
classes because I don't need inheritance).
The intent is that the symbol properties would be defined in another
module. I don't want to fix the 'a in symbol_t here, yet I want to
make an hashtable whose keys are symbols.
In other words,
why the stdlib doesn't give parametrized types for many modules
(Hashtbl, Set...)
when should I use a type constructor with an argument, or a functor?
Any comments?
N.B. Any opinions expressed here are only mine, and not of my organization.
N.B. Les opinions exprimees ici me sont personnelles et n engagent pas le
CEA.
---------------------------------------------------------------------
Basile STARYNKEVITCH ---- Commissariat à l Energie Atomique
DTA/LETI/DEIN/SLA * CEA/Saclay b.528 (p111f) * 91191 GIF/YVETTE CEDEX *
France
phone: 1,69.08.60.55; fax: 1.69.08.83.95 home: 1,46.65.45.53
email: Basile point Starynkevitch at cea point fr
reply other threads:[~1999-07-10 18:05 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=39ADCF833E74D111A2D700805F1951EF0F00BCB6@RED-MSG-06 \
--to=dsyme@microsoft.com \
--cc=caml-list@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