Version française
Home     About     Download     Resources     Contact us    
Browse thread
covariance newb question
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Olivier Andrieu <oandrieu@n...>
Subject: Re: [Caml-list] covariance newb question
 Christophe Raffalli [Monday 28 November 2005] :
 > first 'a -> 'b is covariant in 'a and contravariant in 'b and Ocaml

It's the opposite (contravariant in 'a, covariant in 'b) :

,----
| # type (+'a, -'b) t = 'a -> 'b  ;;
| Characters 5-28:
|   type (+'a, -'b) t = 'a -> 'b  ;;
|        ^^^^^^^^^^^^^^^^^^^^^^^
| In this definition, expected parameter variances are not satisfied.
| The 1st type parameter was expected to be covariant,
| but it is contravariant
| # type (-'a, +'b) t = 'a -> 'b  ;;
| type ('a, 'b) t = 'a -> 'b
`----

-- 
   Olivier