caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Subtype problem
@ 1998-05-20 15:00 Hendrik Tews
  1998-05-22  2:21 ` Jacques GARRIGUE
  0 siblings, 1 reply; 7+ messages in thread
From: Hendrik Tews @ 1998-05-20 15:00 UTC (permalink / raw)
  To: caml-list

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





^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~1998-06-06 22:02 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-05-20 15:00 Subtype problem Hendrik Tews
1998-05-22  2:21 ` Jacques GARRIGUE
1998-05-25 11:46   ` co(ntra)-variant subtyping Hendrik Tews
1998-05-26  9:24     ` Didier Remy
1998-06-04 15:17       ` Hendrik Tews
1998-06-04 18:29         ` Didier Remy
1998-06-05  5:45         ` Jacques GARRIGUE

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).