Browse thread
Why can't I use val mover : < move : int -> unit; .. > list -> unit ?
-
Mattias Waldau
- Brian Rogoff
- Alain Frisch
- Sylvain BOULM'E
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ 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 ? |
Hi, 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. Sylvain.