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