Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
OCaml's long range graphical direction?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Jacques Garrigue <garrigue@k...>
Subject: Re: OCaml's long range graphical direction?
From: Nicolas barnier <>
> Marcin 'Qrczak' Kowalczyk wrote:
> > 
> > What are variance annotations in OCaml?
> Perniciously stolen on the OCaml CVS server (file "Changes"), but I lack
> the new doc ;-):
> Objective Caml 3.01:
> --------------------
> New language features:
> - Variables are allowed in "or" patterns, e.g.
>      match l with [t] | [_;t] -> ... t ...
> - "include <structure expression>" to re-export all components of a
>   structure inside another structure.
> - Variance annotation on parameters of type declarations, e.g.
>     type (+'a,-'b,'c) t (covariant in 'a, contravariant in 'b, invariant in 'c)

Yes, this is the syntax.
Practically, this means that you can now mix object and variant
subtyping with both datatypes and abstract types.

For instance, suppose that you have two types c and d, d subtype of c.
In ocaml 3.00, to coerce a list of d's to a list of c's, you would
have to write (fun x -> (x : d :> c)) l
In ocaml 3.01, you can do it directly
     (l : d list :> c list)
because list is a covariant type, which you can see from its definition.

Not only that, but thanks to explicit variance annotations, even
abstract datatypes, like maps from the Map module, can be traversed by
My remark on a lesser need for "hacked" coercions is a side-effect of

Jacques Garrigue