Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
Functions over polymorphic variants
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Kaspar Rohrer <kaspar.rohrer@g...>
Subject: Functions over polymorphic variants
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 with
	| `x -> Stream.slazy fold
	| #abc as x -> Stream.icons x (Stream.slazy fold)
	Stream.Failure -> Stream.sempty
   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