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: Olivier Andrieu <oandrieu@i...>
Subject: Re: [Caml-list] -'a (doc request)
 david baelde [Wednesday 7 September 2005] :
 >
 > I just saw in cairo.mli a type declaration which I don't understand:
 > type -'a surface
 > What's the difference with 'a ?

This is a variance annotation. From the manual:
,----
| 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
`----

So it means the `surface' type is contravariant wrt the
parameter. This allows the caml API to reflect the subtyping relations
of the underlying C type.

Typically, you have constructor functions:

  val image_surface_create       : ... -> [ `Any | `Image ] surface
  val surface_create_for_channel : ... -> [ `Any | `PDF ] surface

, functions that work on any kind of surface:

  val surface_flush : [> `Any ] surface -> unit

and some functions that are specific to a subtype of surface:

  val image_surface_get_width : [> `Image ] surface -> int

HTH,
-- 
   Olivier