From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id 7A014BB83 for ; Thu, 4 May 2006 19:10:11 +0200 (CEST) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id k44HAB9L013180 for ; Thu, 4 May 2006 19:10:11 +0200 Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id TAA14259 for ; Thu, 4 May 2006 19:10:10 +0200 (MET DST) Received: from yquem.inria.fr (yquem.inria.fr [128.93.8.37]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id k44HAAaU013174; Thu, 4 May 2006 19:10:10 +0200 Received: by yquem.inria.fr (Postfix, from userid 18041) id 35FD0BB83; Thu, 4 May 2006 19:10:10 +0200 (CEST) Date: Thu, 4 May 2006 19:10:10 +0200 To: Jeremy Yallop Cc: caml-list@inria.fr Subject: Re: [Caml-list] Oddness with recursive polymorphic variants Message-ID: <20060504171010.GB23421@yquem.inria.fr> References: <445A23BF.4030001@sms.ed.ac.uk> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <445A23BF.4030001@sms.ed.ac.uk> User-Agent: Mutt/1.5.9i From: luc.maranget@inria.fr (Luc Maranget) X-Miltered: at concorde with ID 445A3573.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at concorde with ID 445A3572.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; recursive:01 variants:01 maranget:01 maranget:01 compiler:01 luc:01 luc:01 polymorphic:01 polymorphic:01 caml-list:01 expression:01 expression:01 variant:02 variant:02 types:02 X-Spam-Checker-Version: SpamAssassin 3.0.3 (2005-04-27) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.0.3 > I have two polymorphic variant types, as follows: > > type f = [`A | `B of f] > type g = [f | `C] > > Next, I have a function from f to g: > > let s1 : f -> g = function > | `A -> `A > | `B b -> b > > Sadly, the compiler rejects this: > > Characters 57-58: > | `B b -> b;; > ^ > This expression has type f but is here used with type g > The first variant type does not allow tag(s) `C > > The error message seems odd. Why should it matter that g has more tags > than f, since every value of f is a value of g (by definition)? I cannot really explain why it matters, but I can supply a minimal (?) example type f = [`A ] type g = [f | `C] let k (x:f) = (x:g);; ^ This expression has type f but is here used with type g The first variant type does not allow tag(s) `C -- Luc