From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by walapai.inria.fr (8.13.6/8.13.6) with ESMTP id p4GDeMZW010237 for ; Mon, 16 May 2011 15:40:22 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgwCACEo0U3RVdQ2imdsb2JhbACYDYYxh08IFAEBAQoJDQcSBiGIcKFgjBqCNYRVN4hiAQEDBoYTBJARiEuCOjuDNw X-IronPort-AV: E=Sophos;i="4.64,374,1301868000"; d="scan'208";a="108694062" Received: from mail-vw0-f54.google.com ([209.85.212.54]) by mail1-smtp-roc.national.inria.fr with ESMTP/TLS/RC4-MD5; 16 May 2011 15:40:17 +0200 Received: by vws18 with SMTP id 18so6270712vws.27 for ; Mon, 16 May 2011 06:39:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc:content-type; bh=e8H/mJpVlXJUpEqh1h8rcKYWGbUJ9ZHOPpDzeKCKCiE=; b=uxL8T5NsFf2Ad8EUaV27aaIB6z6iVgYluS9RvDiI+fi5PJV/k/SStqhuV9mfXL9GFT qHRlP65Ho1iSuH3saLx/Dw9kdOZlv9JP6JvIRGNqN+0MD5sgEavV0bg8s3N04IiISpQ/ psI8Zw85NRLcCYwaRGVTy17eXl9Vml9s5AS3I= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; b=ni0oK5aYlYEqwp/V9nGa0OS0SxlKo17GztNFwoOi4lesHmZeBiYRaeH52DbyiUJAwh Rl0C7ndcf0hPU3AQm52sr8A1NpCpaLw6LGUY00lLcB4frt24zfm7cqn+RHYDCDngoKuQ DB2iAs3/LRCAUK+babs9V5PdAVYXRTBhTf4gc= Received: by 10.52.73.33 with SMTP id i1mr3636489vdv.133.1305553167330; Mon, 16 May 2011 06:39:27 -0700 (PDT) MIME-Version: 1.0 Received: by 10.52.183.136 with HTTP; Mon, 16 May 2011 06:39:07 -0700 (PDT) In-Reply-To: <522E096A-D3D5-466A-A445-AC5932F7B68F@gmail.com> References: <87wrhr9n88.fsf@frosties.localnet> <522E096A-D3D5-466A-A445-AC5932F7B68F@gmail.com> From: Gabriel Scherer Date: Mon, 16 May 2011 15:39:07 +0200 Message-ID: To: Joel Reymont Cc: Goswin von Brederlow , caml-list Content-Type: multipart/alternative; boundary=20cf3071c7e8c62eff04a364c872 Subject: Re: [Caml-list] do i need a private row type? --20cf3071c7e8c62eff04a364c872 Content-Type: text/plain; charset=ISO-8859-1 The problem with this solution, if I understand it correctly, is that it amounts to losing type information. Your values begin with some type information attached to them, that allows more fine-grained typing of some information (subscription), but then you coerce them into a big magma of "everything" to put them in the array, and the type information is lost. When you get back an element of this array, you don't know anymore if it was a `Pair or a `Sub for example. You probably won't be able to use the more restrictive operations of your interface. A solution to this problem would be to tag each item with its provenance type, so that you can regain fine-grained types dynamically : type any_poll = | Pair of pair poll | Sub of sub poll | ... Then, given an array of `any_poll` elements, you can pattern match and, if it's a `Sub`, you have a `sub poll` available. I think this is more precise than your current solution. More generally, I don't think the polymorphic variants bring anything more that what you could have with simple abstract types here. For example to coerce everything to a common type with the `pair poll`, `sub poll` solution you could define a `any` abstract datatype and provide a `val lose_type_info : 'a poll -> any poll` function. Unless I'm mistaken, this is equivalent to your current solution, and shields you of any superfluous polymorphic variant oddities. On Mon, May 16, 2011 at 3:02 PM, Joel Reymont wrote: > Issue solved thanks to Anil Madhavapeddy. > > val pair : [>`Pair] kind > val pub : [>`Pub] kind > > etc. > > and then > > type poll_socket = [`Pair|`Pub|`Sub|`Req|`Rep|`Dealer|`Router|`Pull|`Push] > Socket.t > type poll_item = (poll_socket * event_mask) > > val of_poll_items : poll_item array -> t > > This does it! > > -------------------------------------------------------------------------- > - for hire: mac osx device driver ninja, kernel extensions and usb drivers > ---------------------+------------+--------------------------------------- > http://wagerlabs.com | @wagerlabs | http://www.linkedin.com/in/joelreymont > ---------------------+------------+--------------------------------------- > > > > --20cf3071c7e8c62eff04a364c872 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable The problem with this solution, if I understand it correctly, is that it am= ounts to losing type information. Your values begin with some type informat= ion attached to them, that allows more fine-grained typing of some informat= ion (subscription), but then you coerce them into a big magma of "ever= ything" to put them in the array, and the type information is lost. When you get back an element of this array, you don't know anymore if i= t was a `Pair or a `Sub for example. You probably won't be able to use = the more restrictive operations of your interface.

A solution to this problem would be to tag each item with its provenan= ce type, so that you can regain fine-grained types dynamically :
=
type any_poll =3D
=A0 | Pair of pair poll
=A0 | Sub of sub poll
=A0 | ...

Then, gi= ven an array of `any_poll` elements, you can pattern match and, if it's= a `Sub`, you have a `sub poll` available. I think this is more precise tha= n your current solution.
More generally, I don't think the polymorphic variants bring anyth= ing more that what you could have with simple abstract types here. For exam= ple to coerce everything to a common type with the `pair poll`, `sub poll` = solution you could define a `any` abstract datatype and provide a `val lose= _type_info : 'a poll -> any poll` function. Unless I'm mistaken,= this is equivalent to your current solution, and shields you of any superf= luous polymorphic variant oddities.

On Mon, May 16, 2011 at 3:02 PM, Joel R= eymont <joelr1@gma= il.com> wrote:
Issue solved thanks to Anil Madhavapeddy.

val pair =A0 : [>`Pair] kind
val pub =A0 =A0: [>`Pub] kind

etc.

and then

type poll_socket =3D [`Pair|`Pub|`Sub|`Req|`Rep|`Dealer|`Router|`Pull|`Push= ] Socket.t
type poll_item =3D (poll_socket * event_mask)

val of_poll_items : poll_item array -> t

This does it!

--------------------------------------------------------------------------<= br> - for hire: mac osx device driver ninja, kernel extensions and usb drivers<= br> ---------------------+------------+---------------------------------------<= br> http://wagerlabs.com= | @wagerlabs | http://www.linkedin.com/in/joelreymont
---------------------+------------+---------------------------------------<= br>



--20cf3071c7e8c62eff04a364c872--