From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: ** X-Spam-Status: No, score=2.0 required=5.0 tests=AWL,DNS_FROM_RFC_ABUSE, DNS_FROM_RFC_POST,DNS_FROM_RFC_WHOIS autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by yquem.inria.fr (Postfix) with ESMTP id 17C43BB84 for ; Sat, 31 Jan 2009 17:55:27 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Au0CAPgQhElDww+dnGdsb2JhbACPBoURAQEBAQEICwgJEaR4jikFAgGEEQY X-IronPort-AV: E=Sophos;i="4.37,356,1231110000"; d="scan'208";a="34547275" Received: from web111505.mail.gq1.yahoo.com ([67.195.15.157]) by mail4-smtp-sop.national.inria.fr with SMTP; 31 Jan 2009 17:55:26 +0100 Received: (qmail 7845 invoked by uid 60001); 31 Jan 2009 16:55:24 -0000 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=X-YMail-OSG:Received:X-Mailer:Date:From:Subject:To:MIME-Version:Content-Type:Content-Transfer-Encoding:Message-ID; b=mMsm5MjI9N3wpI+paCe+MG4tZpbCXWQOmxK40M3Ar3KzS7/bNCqz9FM2gAWQ2/Nbj/z4UZRRUYNUhqnZf9h0yp0uT9I5Lv277oy+9QIswJsslEjV9vVFvqcxwqXSQm2479XpdhYxvw848+4RJ6ptHfWIWwhUbzD0x5JUswY0jGo=; X-YMail-OSG: C17hqB0VM1khGpL1bOP2KEpefE.VcmTKDpUU152kg5WW.nvpYn6nsUaevnmx6vAWOibwup14hcidxySpremMC9iKUZJgoRmGP1p8sUgdSrYvt8aml8ns85LbWFRMBJjKxOS6_0N_uFFc34iE8tF715umVJD1MaPuzlaH7MihfvLSNfEDOPjBxJw6Yez17A-- Received: from [213.205.70.197] by web111505.mail.gq1.yahoo.com via HTTP; Sat, 31 Jan 2009 08:55:22 PST X-Mailer: YahooMailWebService/0.7.260.1 Date: Sat, 31 Jan 2009 08:55:22 -0800 (PST) From: Dario Teixeira Subject: Union of type variables To: caml-list@yquem.inria.fr MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Message-ID: <725185.7305.qm@web111505.mail.gq1.yahoo.com> X-Spam: no; 0.00; kludge:01 sig:01 val:01 foo:01 val:01 foo:01 struct:01 foobar:01 foobar:01 kludge:01 presupposes:01 variants:01 polymorphic:01 int:01 int:01 Hi, Consider the following toy experiment with phantom types. Note that the sh= own implementation of function "union" is far from optimal; though it takes onl= y two arguments, these are being passed as a list. This is basically just a kludge that forces the phantom type in the return type to be also a union. module M: sig =09type 'a t =09val a: int -> [> `Foo ] t =09val b: int -> [> `Foo ] t =09val c: int -> [> `Bar ] t =09val d: int -> [> `Bar ] t =09val union: 'a t list -> 'a t end =3D struct =09type foobar_t =3D =09=09| A of int =09=09| B of int =09=09| C of int =09=09| D of int =09=09| Union of foobar_t * foobar_t =09type 'a t =3D foobar_t =09let a x =3D A x =09let b x =3D B x =09let c x =3D C x =09let d x =3D D x =09let union (x :: y :: []) =3D Union (x, y) end 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 =3D Union (x, y) Thanks in advance! Best regards, Dario Teixeira =0A=0A=0A