English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

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: 2010-03-23 (02:53)
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.next 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