From: Hendrik Tews <tews@tcs.inf.tu-dresden.de>
To: caml-list@inria.fr
Subject: Subtype problem
Date: Wed, 20 May 1998 17:00:12 +0200 [thread overview]
Message-ID: <199805201500.RAA19129@ithif18.inf.tu-dresden.de> (raw)
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
next reply other threads:[~1998-05-21 12:31 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
1998-05-20 15:00 Hendrik Tews [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=199805201500.RAA19129@ithif18.inf.tu-dresden.de \
--to=tews@tcs.inf.tu-dresden.de \
--cc=caml-list@inria.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox