Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: rossberg@ps.uni-sb.de
To: "caml-list" <caml-list@inria.fr>
Subject: Re: [Caml-list] How to compute variance of a type
Date: Sun, 6 Jan 2008 13:44:50 +0100 (CET)	[thread overview]
Message-ID: <52628.77.11.133.208.1199623490.squirrel@www.ps.uni-sb.de> (raw)
In-Reply-To: <c1490a380801060219hc074ad0s46db833fa4410fe8@mail.gmail.com>

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


  reply	other threads:[~2008-01-06 12:44 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-01-06 10:19 Tom Primožič
2008-01-06 12:44 ` rossberg [this message]
2008-01-06 15:31 ` [Caml-list] " Andrej Bauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=52628.77.11.133.208.1199623490.squirrel@www.ps.uni-sb.de \
    --to=rossberg@ps.uni-sb.de \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox