From: Alan Schmitt <alan.schmitt@polytechnique.org>
To: Will M Farr <farr@mit.edu>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] A (Silly?) Question About Universal Type Quantification
Date: Thu, 10 Sep 2009 17:51:00 +0200 [thread overview]
Message-ID: <25ec8ca60909100851o4495ec29t101970ef00b0294@mail.gmail.com> (raw)
In-Reply-To: <CFC43205-B409-43C9-B796-91BC386BCC9E@MIT.EDU>
[-- Attachment #1: Type: text/plain, Size: 1169 bytes --]
On Thu, Sep 10, 2009 at 5:00 PM, Will M Farr <farr@mit.edu> wrote:
> 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.
Interestingly, I had the same problem recently where I wanted to create a
list of "tests" that could access some extra information when run (and
would also return a list of tests to run later). I found that using a class
type worked well:
class type test =
object
method name : string
method run : (test * float) list
end
To define a test, I simply do:
let test_download : Timed_events.test =
object (self)
val mutable cache = 0 (* anything I want *)
method name = "Download"
method run =
(* From here I can access the cache and plan to run the test again in
10 seconds *)
[self, 10.0]
end
Alan
[-- Attachment #2: Type: text/html, Size: 1731 bytes --]
prev parent reply other threads:[~2009-09-10 15:51 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-09-10 15:00 Will M Farr
2009-09-10 15:48 ` [Caml-list] " Martin Jambon
2009-09-10 15:51 ` Alan Schmitt [this message]
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=25ec8ca60909100851o4495ec29t101970ef00b0294@mail.gmail.com \
--to=alan.schmitt@polytechnique.org \
--cc=caml-list@inria.fr \
--cc=farr@mit.edu \
/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