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.5 required=5.0 tests=AWL,NO_REAL_NAME autolearn=disabled version=3.1.3 Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by yquem.inria.fr (Postfix) with ESMTP id 2D7F4BC6B for ; Sun, 6 Jan 2008 13:44:55 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAAGZbgEfAXQInh2dsb2JhbACPJHYBAQEICimXKw X-IronPort-AV: E=Sophos;i="4.24,250,1196636400"; d="scan'208";a="6325564" Received: from concorde.inria.fr ([192.93.2.39]) by mail1-smtp-roc.national.inria.fr with ESMTP; 06 Jan 2008 13:44:54 +0100 Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by concorde.inria.fr (8.13.6/8.13.6) with ESMTP id m06Ciqtp023161 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=OK) for ; Sun, 6 Jan 2008 13:44:54 +0100 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Ah4FAGZbgEeGYAcfbGdsb2JhbACPJHYLBAYQGZcr X-IronPort-AV: E=Sophos;i="4.24,250,1196636400"; d="scan'208";a="5760920" Received: from theia.rz.uni-saarland.de ([134.96.7.31]) by mail2-smtp-roc.national.inria.fr with ESMTP; 06 Jan 2008 13:44:52 +0100 Received: from uni-sb.de (uni-sb.de [134.96.7.230]) by theia.rz.uni-saarland.de (8.14.1/8.14.0) with ESMTP id m06CipnP016732 for ; Sun, 6 Jan 2008 13:44:51 +0100 Received: from mail.cs.uni-sb.de (mail.cs.uni-sb.de [134.96.254.200]) by uni-sb.de (8.14.2/2007110200) with ESMTP id m06CipuK004275 for ; Sun, 6 Jan 2008 13:44:51 +0100 (CET) Received: from mail.ps.uni-sb.de (james.ps.uni-sb.de [134.96.186.68]) by mail.cs.uni-sb.de (8.14.2/2007112900) with ESMTP id m06Cipqd027745 for ; Sun, 6 Jan 2008 13:44:51 +0100 (CET) Received: from localhost ([127.0.0.1] helo=www.ps.uni-sb.de ident=www-data) by mail.ps.uni-sb.de with esmtp (Exim 4.63) (envelope-from ) id 1JBUry-0000ny-QU for caml-list@inria.fr; Sun, 06 Jan 2008 13:44:50 +0100 Received: from 77.11.133.208 (SquirrelMail authenticated user rossberg) by www.ps.uni-sb.de with HTTP; Sun, 6 Jan 2008 13:44:50 +0100 (CET) Message-ID: <52628.77.11.133.208.1199623490.squirrel@www.ps.uni-sb.de> In-Reply-To: References: Date: Sun, 6 Jan 2008 13:44:50 +0100 (CET) Subject: Re: [Caml-list] How to compute variance of a type From: rossberg@ps.uni-sb.de To: "caml-list" User-Agent: SquirrelMail/1.4.9a MIME-Version: 1.0 Content-Type: text/plain;charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Priority: 3 (Normal) Importance: Normal X-SA-Exim-Connect-IP: 127.0.0.1 X-SA-Exim-Mail-From: rossberg@ps.uni-sb.de X-SA-Exim-Scanned: No (on mail.ps.uni-sb.de); SAEximRunCond expanded to false X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-3.0 (theia.rz.uni-saarland.de [134.96.7.31]); Sun, 06 Jan 2008 13:44:51 +0100 (CET) X-AntiVirus: checked by AntiVir MailGate (version: 2.1.2-14; AVE: 7.6.0.46; VDF: 7.0.1.194; host: AntiVir1) X-Miltered: at concorde with ID 4780CD44.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; rossberg:01 funct:01 funct:01 recursive:01 wrote:01 andreas:01 caml-list:01 constructor:01 algorithm:01 argument:02 argument:02 covariant:02 covariant:02 uni-sb:03 complex:05 Tom Primožič wrote: > > But I have no idea on how to compute variance of complex types, like > > type ('a, 'b, 'c) long_funct = ('a -> 'b) -> 'c > > since the whole ('a -> 'b) is in contravariant position, so 'a is twice contravariant, > and b is first contra-, and the covariant. > > Any resources? Off-hand I don't have any easy resources I could point to, but the basic rule is very simple: whenever you descent into a type argument where the respective type constructor has negative polarity (like the left argument of "->"), you just negate the variances. Thus, in your example, long_funct is covariant in 'a and 'c, and contravariant in 'b. It is straightforward to formulate that as a recursive algorithm. - Andreas