Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Jacques Garrigue <garrigue@math.nagoya-u.ac.jp>
To: remi.vanicat@gmail.com
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Object typing
Date: Mon, 11 Jul 2005 17:22:42 +0900 (JST)	[thread overview]
Message-ID: <20050711.172242.133294018.garrigue@math.nagoya-u.ac.jp> (raw)
In-Reply-To: <6b8a9142050711001847d520c8@mail.gmail.com>

From: Remi Vanicat <remi.vanicat@gmail.com>

> Notice that one can do better than this :
> # class [+'a] entity =
> object
>  method is_a (v:'a) = (v = `Entity)
> end;;
>      class ['a] entity :
>   object constraint 'a = [> `Entity ] method is_a : 'a -> bool end
> # let e = new entity;;
> val e : [> `Entity ] entity = <obj>
> 
> now we don't have an _ type, and there is no need to close it before
> the end of the program.

Thank you for finding a serious bug in the variance check!
Didn't it strike you as strange that a method parameter could be
declared with a covariant type? This goes clearly against the
definition.
The problem was that the variance check omitted the row-variable in
variants, so that if a variant constraint is used on a type parameter,
any variance is accepted...

After fixing this in CVS for 3.08.4, you get rightfully:
  In this definition, a type variable has a variance that is not reflected
  by its occurence in type parameters.
or in 3.09
  In this definition, expected parameter variances are not satisfied

If you really want to make it covariant, you should define is_a out of
the class:

# class [+'a] entity =
  object
    method classes : 'a = [`Entity]
  end;;
class ['a] entity :
  object constraint 'a = [> `Entity ] list method classes : 'a end
# let e = new entity;;
val e : [> `Entity ] list entity = <obj>
# let is_a ob cl = List.mem cl ob#classes;;
val is_a : < classes : 'a list; .. > -> 'a -> bool = <fun>

(And be careful about the above bug before 3.08.4.)

Jacques Garrigue

P.S. I really think that the variance check is now OK, but if you find
strange behaviours in typing, please report them. Particularly when
something that shouldn't type is accepted.


  reply	other threads:[~2005-07-11  8:22 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-07-09 23:55 Matthew O'Connor
2005-07-10  0:20 ` [Caml-list] " Pietro Abate
2005-07-10  6:19   ` Matthew O'Connor
2005-07-10 18:25 ` Stephane Glondu
2005-07-10 22:06 ` Christophe TROESTLER
2005-07-11  6:23   ` Matthew O'Connor
2005-07-11  7:18   ` Remi Vanicat
2005-07-11  8:22     ` Jacques Garrigue [this message]
2005-07-11  9:16       ` Marcin 'Qrczak' Kowalczyk

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=20050711.172242.133294018.garrigue@math.nagoya-u.ac.jp \
    --to=garrigue@math.nagoya-u.ac.jp \
    --cc=caml-list@inria.fr \
    --cc=remi.vanicat@gmail.com \
    /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