# Subtype problem

From: Hendrik Tews (tews@tcs.inf.tu-dresden.de)
Date: Wed May 20 1998 - 17:00:12 MET DST

Date: Wed, 20 May 1998 17:00:12 +0200
Message-Id: <199805201500.RAA19129@ithif18.inf.tu-dresden.de>
From: Hendrik Tews <tews@tcs.inf.tu-dresden.de>
To: caml-list@inria.fr
Subject: Subtype problem

Hi,

could somebody tell me, why

-------------------------Version 1---------------------------
class point x =
val mutable x = (x : int)
method x = x
method move (i : int) = {< x = x + i >}
end;;

class colored_point x c =
val mutable x = (x : int)
val color = (c : int)
method x = x
method move (i : int) = {< x = x + i >}
method color = color
end;;

let p = ((new colored_point 2 1 :> point) : point)
-------------------------Version 1---------------------------

compiles without problem, while

-------------------------Version 2---------------------------
class point x =
val mutable x = (x : int)
method x = x
method move (i : int) = Some {< x = x + i >}
end;;

class colored_point x c =
val mutable x = (x : int)
val color = (c : int)
method x = x
method move (i : int) = Some {< x = x + i >}
method color = color
end;;

let p = ((new colored_point 2 1 :> point) : point)
-------------------------Version 2---------------------------

produces an error? (The only difference is the move method, which
delivers an option in version 2). The error message is

-------------------------Error-------------------------------
This expression cannot be coerced to type
point = < x : int; move : int -> point option >;
it has type
colored_point =
< x : int; move : int -> colored_point option; color : int >
but is here used with type
< x : int; move : int -> point option; color : int >
Type
colored_point =
< x : int; move : int -> colored_point option; color : int >
is not compatible with type point = < x : int; move : int -> point option >
-------------------------Error-------------------------------

Bye,

Hendrik

This archive was generated by hypermail 2b29 : Sun Jan 02 2000 - 11:58:14 MET