From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by walapai.inria.fr (8.13.6/8.13.6) with ESMTP id p4G6PEtm023859 for ; Mon, 16 May 2011 08:25:14 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AtUDAObC0E3ZSMDdgmdsb2JhbACmExQBAQkNCQcWAyKIcL05hhkElECEHIYs X-IronPort-AV: E=Sophos;i="4.64,373,1301868000"; d="scan'208";a="83256130" Received: from fmmailgate01.web.de ([217.72.192.221]) by mail3-smtp-sop.national.inria.fr with ESMTP; 16 May 2011 08:24:40 +0200 Received: from smtp04.web.de ( [172.20.0.225]) by fmmailgate01.web.de (Postfix) with ESMTP id 3DD1618F06F53; Mon, 16 May 2011 08:24:40 +0200 (CEST) Received: from [78.43.204.177] (helo=frosties.localnet) by smtp04.web.de with asmtp (TLSv1:AES256-SHA:256) (WEB.DE 4.110 #2) id 1QLrEO-0007IC-00; Mon, 16 May 2011 08:24:40 +0200 Received: from mrvn by frosties.localnet with local (Exim 4.72) (envelope-from ) id 1QLrEN-0004rL-Jz; Mon, 16 May 2011 08:24:39 +0200 From: Goswin von Brederlow To: Joel Reymont Cc: caml-list References: Date: Mon, 16 May 2011 08:24:39 +0200 In-Reply-To: (Joel Reymont's message of "Sun, 15 May 2011 15:56:50 +0200") Message-ID: <87wrhr9n88.fsf@frosties.localnet> User-Agent: Gnus/5.110009 (No Gnus v0.9) XEmacs/21.4.22 (linux, no MULE) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Sender: goswin-v-b@web.de X-Sender: goswin-v-b@web.de X-Provags-ID: V01U2FsdGVkX18aG8B/k0Ij0AvbGxTYLESf9+p8YX6pjgatpIMv 6WDsHDoTdosLmWxHnQYrAOwG329VVqqC4Xixvg7F+seDEfWTRD kzmgqwN7g= Subject: Re: [Caml-list] do i need a private row type? Joel Reymont 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