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
Union of type variables
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2009-02-02 (17:07)
From: Dario Teixeira <darioteixeira@y...>
Subject: Re: [Caml-list] Union of type variables

> Obviously I would like to get rid of this kludge.  The signature and
> implementation for "union" should be something like the (syntactically
> incorrect) code below.  But is it at all possible to declare an union
> of type variables?  (which presupposes they are polymorphic variants)
> val union: 'x t -> 'y t -> [> 'x |
> 'y ] t
> let union x y = Union (x, y)

In the meantime I realised what the problem was.  I neglected to take
into account the open nature of polymorphic variants, meaning that as
long as the phantom type variable is open, then the following code is
enough to do what I want:

val union: 'a t -> 'a t -> 'a t
let union x y = Union (x, y)

Dario Teixeira