caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Jacques GARRIGUE <garrigue@kurims.kyoto-u.ac.jp>
To: tews@tcs.inf.tu-dresden.de
Cc: caml-list@inria.fr
Subject: Re: Subtype problem
Date: Fri, 22 May 1998 11:21:57 +0900	[thread overview]
Message-ID: <19980522112157L.garrigue@kurims.kyoto-u.ac.jp> (raw)
In-Reply-To: Your message of "Wed, 20 May 1998 17:00:12 +0200" <199805201500.RAA19129@ithif18.inf.tu-dresden.de>

From: Hendrik Tews <tews@tcs.inf.tu-dresden.de>

> 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 

Objective Caml's subtyping algorithm does not subtype under type
constructors (but it does it under abbreviations), for the sake of
efficiency. That is, eventhough colored_point :> point, you don't have
colored_point option :> point option. This equation would be needed to
check the subtyping in method move of example 2.

By the way, Objective Label does it, so that

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

would work for the second example. You need to write a complete
coercion (with both types), since doing this for partial coercions
would lead to huge types, and very slow inference.

	Jacques

---------------------------------------------------------------------------
Jacques Garrigue      Kyoto University     garrigue at kurims.kyoto-u.ac.jp
		<A HREF=http://wwwfun.kurims.kyoto-u.ac.jp/~garrigue/>JG</A>





  reply	other threads:[~1998-05-23 22:15 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1998-05-20 15:00 Hendrik Tews
1998-05-22  2:21 ` Jacques GARRIGUE [this message]
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=19980522112157L.garrigue@kurims.kyoto-u.ac.jp \
    --to=garrigue@kurims.kyoto-u.ac.jp \
    --cc=caml-list@inria.fr \
    --cc=tews@tcs.inf.tu-dresden.de \
    /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;
as well as URLs for NNTP newsgroup(s).