From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id RAA10314; Fri, 30 Aug 2002 17:50:21 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id RAA10604 for ; Fri, 30 Aug 2002 17:50:20 +0200 (MET DST) Received: from lobus.fungible.com (adsl-64-161-114-6.dsl.snfc21.pacbell.net [64.161.114.6]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id g7UFoID25299 for ; Fri, 30 Aug 2002 17:50:19 +0200 (MET DST) Received: by lobus.fungible.com (Postfix, from userid 1000) id 90B527F63; Fri, 30 Aug 2002 08:50:16 -0700 (PDT) Date: Fri, 30 Aug 2002 08:34:25 -0700 From-Tims-Fingers: true To: caml-list@inria.fr Subject: [Caml-list] Polymorphic variants as type parameters Message-Id: <20020830155016.90B527F63@lobus.fungible.com> From: tim@fungible.com (Tim Freeman) Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Here's some code that I'd like to be able to compile: type eventtype = [`VECTOR | `SCALAR | `UNIT] type +'a eventid constraint 'a = [> eventtype ] type scalar_eventid = [`SCALAR] eventid Unfortunately it gives me an error: Characters 124-133: type scalar_eventid = [`SCALAR] eventid ^^^^^^^^^ This type [ `SCALAR] should be an instance of type [> eventtype] = [> `SCALAR | `UNIT | `VECTOR] The first variant type does not allow tag(s) `UNIT, `VECTOR This feels like a bug to me: I said the type variable was covariant, and the type I'm substituting for the type variable is more specific than the old one, so I had expected it to be happy with that. The present workaround I'm using is to leave out the type constraint on the type argument to eventid: type eventtype = [`VECTOR | `SCALAR | `UNIT] type +'a eventid type scalar_eventid = [`SCALAR] eventid This doesn't say what I want because it only makes sense for the type argument to eventid to be some subset of the set {`VECTOR, `SCALAR, `UNIT}. Another approach to getting the code to compile is to give scalar_eventid a type parameter. This compiles but it doesn't say what I want to say because scalar_eventid shouldn't have a type parameter; that would force my code to grow useless extra type variables in lots of places. type eventtype = [`VECTOR | `SCALAR | `UNIT] type +'a eventid constraint 'a = [> eventtype ] type 'a scalar_eventid = 'a eventid constraint 'a = [> `SCALAR ] Is there any way to say what I want to say in OCAML? Is this as a bug? -- Tim Freeman tim@fungible.com GPG public key fingerprint ECDF 46F8 3B80 BB9E 575D 7180 76DF FE00 34B1 5C78 ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners