From: Christophe Raffalli <raffalli@univ-savoie.fr>
To: Christophe Papazian <christophe.papazian@gmail.com>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] covariance newb question
Date: Mon, 28 Nov 2005 00:31:01 +0100 [thread overview]
Message-ID: <438A41B5.3060206@univ-savoie.fr> (raw)
In-Reply-To: <5FABF242-1101-4499-8CF5-CF1559F6EECC@essi.fr>
Christophe Papazian a écrit :
> # type +'a t = 'a -> 'a;;
> In this definition, expected parameter variances are not satisfied.
> The 1st type parameter was expected to be covariant, but it is invariant
>
>
> But type t seems to be covariant :
>
nice question from a newb ;-) and no that trivial !!
fits 'a -> 'b is covariant in 'a and contravariant in 'b and Ocaml
is a stupid compiler (;-) and from this it thinks that 'a -> 'a is
neither covariant nor contravariant.
But that does not prove that 'a -> 'a is not covariant, so we need to
build a counter example.
We have to find two type a and b such that a <: b
and a function in a -> a that is not in b -> b.
That is easy with polymorphic variant:
type a = [ `A] and b = [`A | `B]
let f `A = `A (f has type a -> a but not b -> b)
if you want to show that it is not contravariant, you can take
let g = function `A -> `B | `B -> `A (g has type b -> b but not a -> a)
... now the challenge ... prove that 'a -> 'a is not covariant using only
ML polymorphism (that is no polymorphic variant, modules, object, but only
subtyping on type scheme by substitution) which is probably what you had
in mind with your exemple bellow:
> # let f : 'a t = (fun x -> x);;
> val f : 'a t = <fun>
> # let g : int t = f;;
> val g : int t = <fun>
>
I do not see a solution immediately, because ML polymorphism is too weak
compared to system F
> Is there something wrong in my thought ?
>
Nothing it was a nice thought ... and may work in a small enough
fragment of ML
> thank you,
>
> Christophe Papazian
>
> _______________________________________________
> Caml-list mailing list. Subscription management:
> http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
> Archives: http://caml.inria.fr
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs
next prev parent reply other threads:[~2005-11-27 23:30 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-11-22 11:37 Christophe Papazian
2005-11-23 12:16 ` [Caml-list] " Keiko Nakata
2005-11-27 23:31 ` Christophe Raffalli [this message]
2005-11-28 7:09 ` Olivier Andrieu
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=438A41B5.3060206@univ-savoie.fr \
--to=raffalli@univ-savoie.fr \
--cc=caml-list@inria.fr \
--cc=christophe.papazian@gmail.com \
/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