caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Kaspar Rohrer <kaspar.rohrer@gmail.com>
To: caml-list@inria.fr
Subject: Functions over polymorphic variants
Date: Tue, 23 Mar 2010 03:53:10 +0100	[thread overview]
Message-ID: <D9CF4E35-720D-4CB2-B213-4B4B61CEA32E@bluewin.ch> (raw)

I am tinkering with streams of polymorphic variants at the moment. One thing that I would like to do is to write a stream transformer (not sure this is the correct terminology) that simply drops certain values of an open polymorphic type, and have the type of the function reflect this.

This is trivial with a closed polymorphic type:

type abc = [`a | `b | `c]

let transform (stream : [< `x | abc] Stream.t) : [> abc] Stream.t =
 let rec fold () =
     match Stream.next stream with
	| `x -> Stream.slazy fold
	| #abc as x -> Stream.icons x (Stream.slazy fold)
   with
	Stream.Failure -> Stream.sempty
 in
   fold ()

However, I fail to see how the same function could be implemented so it accepts an open polymorphic type as it's input.
I.e. is there a way to express something like this (which is not valid OCaml)

let transform : [> `x | 'a] Stream.t -> [> 'a] Stream.t

Does this even make sense?

----
Kaspar Rohrer
kaspar.rohrer@bluewin.ch


             reply	other threads:[~2010-03-23  2:53 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-03-23  2:53 Kaspar Rohrer [this message]
2010-03-23  6:11 ` [Caml-list] " Jacques Garrigue
2010-03-23 19:46   ` Kaspar Rohrer

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=D9CF4E35-720D-4CB2-B213-4B4B61CEA32E@bluewin.ch \
    --to=kaspar.rohrer@gmail.com \
    --cc=caml-list@inria.fr \
    /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).