English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
Why can't I use val mover : < move : int -> unit; .. > list -> unit ?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2001-01-11 (09:33)
From: Sylvain BOULM'E <Sylvain.Boulme@l...>
Subject: Re: Why can't I use val mover : < move : int -> unit; .. > list -> unit ?

Lists are polymorphic but they are uniform : elements of a list must have all 
the same type (which can be any type).

Hence, "mover" is a function that expects a list of objects, all of the same 
type, and which type contains a method "move".

Thus, with 
 q: p1d_1
 p: p1d_2

Expression "[q;q]" is of type "p1d_1 list" and "[p;p]" is of type "p1d_2 list",
thus "mover [q;q]" and "mover [p;p]" are well-typed.

But "[p;q]" is not well-typed.

Here, p1d_2 is subtype of p1d_1 : you can coerce p to have the type p1d_1.
Thus "[(p:>p1d_1);q]" is of type p1d_1 list.
And "mover [(p:>p1d_1);q]" is well-typed.