Version française
Home     About     Download     Resources     Contact us    
Browse thread
-'a (doc request)
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: David MENTRE <david.mentre@g...>
Subject: Re: [Caml-list] -'a (doc request)
Hello David,

2005/9/7, david baelde <david.baelde@gmail.com>:
> I just saw in cairo.mli a type declaration which I don't understand:
> type -'a surface
> What's the difference with 'a ?

See http://caml.inria.fr/pub/docs/manual-ocaml/manual016.html#s:type-defs
[the copy/paste is missing greek letters, look at the web page]

The type variables appearing as type parameters can optionally be
prefixed by + or - to indicate that the type constructor is covariant
or contravariant with respect to this parameter. This variance
information is used to decide subtyping relations when checking the
validity of >: coercions (see section 6.7.5).

For instance, type +'a t declares t as an abstract type that is
covariant in its parameter; this means that if the type t is a subtype
of the type s, then t t is a subtype of s t. Similarly, type -'a t
declares that the abstract type t is contravariant in its parameter:
if t is subtype of s, then s t is subtype of t t. If no + or -
variance annotation is given, the type constructor is assumed
invariant in the corresponding parameter. For instance, the abstract
type declaration type 'a t means that t t is neither a subtype nor a
supertype of s t if t is subtype of s.

The variance indicated by the + and - annotations on parameters are
required only for abstract types. For abbreviations, variant types or
record types, the variance properties of the type constructor are
inferred from its definition, and the variance annotations are only
checked for conformance with the definition.


Yours,
d.