From: Goswin von Brederlow <goswin-v-b@web.de>
To: Joel Reymont <joelr1@gmail.com>
Cc: caml-list <caml-list@inria.fr>
Subject: Re: [Caml-list] do i need a private row type?
Date: Mon, 16 May 2011 08:24:39 +0200 [thread overview]
Message-ID: <87wrhr9n88.fsf@frosties.localnet> (raw)
In-Reply-To: <F2D1D152-1088-4E6F-8267-AD6510FE10BD@gmail.com> (Joel Reymont's message of "Sun, 15 May 2011 15:56:50 +0200")
Joel Reymont <joelr1@gmail.com> writes:
> https://github.com/wagerlabs/ocaml-zmq/blob/master/src/ZMQ.ml
>
> Looking at the Poll module at the bottom and the definition of poll_item as
>
> type 'a poll_item = ('a Socket.t * event_mask)
>
> I would like to be able to put different 'a in the same poll_item array.
>
> This is not possible as written, e.g.
>
> Error: This expression has type
> ZMQ.Socket.pub ZMQ.Socket.t * ZMQ.Poll.event_mask
> but an expression was expected of type
> ZMQ.Socket.pull ZMQ.Socket.t * ZMQ.Poll.event_mask
>
> How do I type poll_item and poll_item array so that the array is polymorphic with respect to 'a?
>
> Does the definition of Socket a the top of ZMQ.ml need to be changed to make this possible?
>
> Thanks, Joel
How clean do you want this to be? Lets go with easy and dirty.
First thing is that if you have different 'a poll_items then you need to
include a callback that accepts a matching 'a Socket.t. E.g.:
type 'a poll_item = ('a Socket.t * event_mask * ('a Socket.t -> event_mask -> unit))
Then you can make an unit poll_item array and use
let set i (item : 'a poll_item) =
array.[i] <- Obj.magic item
let call i =
let (sock, mask, fn) = array.[i]
in
fn sock mask
The important part here is that you ensure the 'a Socket.t is only
accessed through the callback. Only that will have the right type.
If you want to make it clean then you need a 2 layer approach with 2
records and 'a. 'a -> 'b style types. I can't remember how to do this
from memory but search the list archive for something like universal
container. I've asked the same a few years back.
MfG
Goswin
next prev parent reply other threads:[~2011-05-16 6:25 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-05-15 13:56 Joel Reymont
2011-05-16 6:24 ` Goswin von Brederlow [this message]
2011-05-16 7:07 ` Gabriel Scherer
2011-05-16 8:57 ` Joel Reymont
2011-05-16 9:31 ` Joel Reymont
2011-05-16 9:58 ` Joel Reymont
2011-05-16 10:05 ` Joel Reymont
2011-05-16 12:02 ` Joel Reymont
2011-05-16 12:32 ` Joel Reymont
2011-05-16 13:02 ` Joel Reymont
2011-05-16 13:39 ` Gabriel Scherer
2011-05-16 13:46 ` Joel Reymont
2011-05-16 14:02 ` Joel Reymont
2011-05-16 14:06 ` Gabriel Scherer
2011-05-16 14:08 ` Joel Reymont
2011-05-17 4:26 ` Goswin von Brederlow
2011-05-19 4:15 ` Pedro Borges
2011-05-19 7:33 ` Joel Reymont
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=87wrhr9n88.fsf@frosties.localnet \
--to=goswin-v-b@web.de \
--cc=caml-list@inria.fr \
--cc=joelr1@gmail.com \
/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