caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Functions over polymorphic variants
@ 2010-03-23  2:53 Kaspar Rohrer
  2010-03-23  6:11 ` [Caml-list] " Jacques Garrigue
  0 siblings, 1 reply; 3+ messages in thread
From: Kaspar Rohrer @ 2010-03-23  2:53 UTC (permalink / raw)
  To: caml-list

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


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2010-03-23 19:46 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-03-23  2:53 Functions over polymorphic variants Kaspar Rohrer
2010-03-23  6:11 ` [Caml-list] " Jacques Garrigue
2010-03-23 19:46   ` Kaspar Rohrer

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).