From: Will M Farr <farr@MIT.EDU>
To: caml-list@inria.fr
Subject: A (Silly?) Question About Universal Type Quantification
Date: Thu, 10 Sep 2009 11:00:35 -0400 [thread overview]
Message-ID: <CFC43205-B409-43C9-B796-91BC386BCC9E@MIT.EDU> (raw)
[-- Attachment #1: Type: text/plain, Size: 1121 bytes --]
Hello,
I recently encountered a situation where I had (effectively) the
following polymorphic type:
type 'a record = { id : int; data : 'a }
and the following compare function
let compare {id = id1} {id = id2} = Pervasives.compare id1 id2
and wanted to put such records into a set. However, I could not
figure out how to make the polymorphic 'a in the type definition
"disappear" in the module argument to the Set.Make functor. For
example, the obvious
Set.Make(struct
type t = 'a record
let compare = compare
end)
fails because the 'a in the type definition for t is unbound. Is
there no way to do this? I'm thinking of some sort of "forall"
designation, which universally quantifies the type parameter, like
Set.Make(struct
type t = forall 'a : 'a record
let compare = compare
end)
(I'm sure that there is better terminology for this---please pardon my
ignorance about types and type theory.)
I ended up solving my problem by placing the record type into a
functor, whose argument specified the concrete type for data, but I'm
curious if other solutions exist.
Thanks,
Will
[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 203 bytes --]
next reply other threads:[~2009-09-10 15:01 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-09-10 15:00 Will M Farr [this message]
2009-09-10 15:48 ` [Caml-list] " Martin Jambon
2009-09-10 15:51 ` Alan Schmitt
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=CFC43205-B409-43C9-B796-91BC386BCC9E@MIT.EDU \
--to=farr@mit.edu \
--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