caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Gabriel Scherer <gabriel.scherer@gmail.com>
To: Joel Reymont <joelr1@gmail.com>
Cc: Goswin von Brederlow <goswin-v-b@web.de>, caml-list <caml-list@inria.fr>
Subject: Re: [Caml-list] do i need a private row type?
Date: Mon, 16 May 2011 15:39:07 +0200	[thread overview]
Message-ID: <BANLkTinJ430ee7=TN9mNQmghPjYU0U+STA@mail.gmail.com> (raw)
In-Reply-To: <522E096A-D3D5-466A-A445-AC5932F7B68F@gmail.com>

[-- Attachment #1: Type: text/plain, Size: 2198 bytes --]

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 <joelr1@gmail.com> 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
> ---------------------+------------+---------------------------------------
>
>
>
>

[-- Attachment #2: Type: text/html, Size: 2911 bytes --]

  reply	other threads:[~2011-05-16 13:40 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
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 [this message]
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='BANLkTinJ430ee7=TN9mNQmghPjYU0U+STA@mail.gmail.com' \
    --to=gabriel.scherer@gmail.com \
    --cc=caml-list@inria.fr \
    --cc=goswin-v-b@web.de \
    --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;
as well as URLs for NNTP newsgroup(s).