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=0.4 required=5.0 tests=AWL,DNS_FROM_RFC_ABUSE autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from discorde.inria.fr (discorde.inria.fr [192.93.2.38]) by yquem.inria.fr (Postfix) with ESMTP id C106CBC68 for ; Wed, 25 Oct 2006 09:18:06 +0200 (CEST) Received: from rabbit.math.nagoya-u.ac.jp (rabbit.math.nagoya-u.ac.jp [133.6.130.5]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id k9P7I4fP004042 for ; Wed, 25 Oct 2006 09:18:06 +0200 Received: from localhost (millas [172.16.30.29]) by rabbit.math.nagoya-u.ac.jp (8.12.11/3.7W) with ESMTP id k9P7HnC6008328; Wed, 25 Oct 2006 16:17:49 +0900 (JST) Date: Wed, 25 Oct 2006 16:16:05 +0900 (JST) Message-Id: <20061025.161605.189731925.garrigue@math.nagoya-u.ac.jp> To: till.varoquaux@gmail.com Cc: caml-list@yquem.inria.fr Subject: Re: [Caml-list] Simple(?) subtyping problem... From: Jacques Garrigue In-Reply-To: <9d3ec8300610242303q44cf7ec1pec711f530616f16a@mail.gmail.com> References: <9d3ec8300610241345k1600fd9dqe3a3bba5c4bd9def@mail.gmail.com> <20061025.074628.104028766.garrigue@math.nagoya-u.ac.jp> <9d3ec8300610242303q44cf7ec1pec711f530616f16a@mail.gmail.com> X-Mailer: Mew version 4.0.69 on Emacs 22.0.50 / Mule 5.0 (SAKAKI) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Miltered: at discorde with ID 453F0FAC.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; subtyping:01 functors:01 afaik:01 functor:01 sig:01 compiler:01 ocaml:01 testlabl:01 cvs:01 polymorphic:01 polymorphic:01 caml-list:01 experimental:01 evaluator:01 variant:02 From: "Till Varoquaux" > This would work but it isn't an option since I cannot get it to work > with functors etc... > AFAIK there's no way to specify a type must be a polymorphic variant > without specfying any of it's members: > > if we are building a functor against: > > module type Evaluator= > sig > ... > type 'a exp (*Is an exact polymorphic variant type *) > ... > end > > we won't be able to write something like: > > type 'a t=[ `Some_label of 'a | 'a exp ] > > since the compiler won't be able to detect 'a exp was a polymorphic > variant (note: it looks like there could also be an issue on the > freshness of the new label) There is indeed an issue of freshness :-) There is code doing exactly what you ask for inside a branch in the CVS for ocaml. The branch is still experimental, and is called varunion. You would have to write type 'a exp = private [> ] ~ [`Some_label of 'a] (* `Some_label may only have type 'a (if present) *) or type 'a exp = private [> ] ~ [`Some_label of 'a] (* `Some_label is absent *) in order to be able to use it later in combination with `Some_label. You can look at the code in testlabl/varunion.ml, which includes examples corresponding exactly to the code you are trying to write. Jacques Garrigue