From: Jacques Garrigue <garrigue@math.nagoya-u.ac.jp>
To: radzevich.belevich@gmail.com
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] class type param constraint
Date: Thu, 09 Apr 2009 19:13:06 +0900 (JST) [thread overview]
Message-ID: <20090409.191306.169484516.garrigue@math.nagoya-u.ac.jp> (raw)
In-Reply-To: <1239266526.2787.5.camel@serphost.localdomain>
From: Radzevich Belevich <radzevich.belevich@gmail.com>
> class [ 'c ] a =
> object(self)
> constraint 'c = < .. >
> method as_c = (self :> 'c)
> method id = Oo.id self
> end ;;
> class ['a] a :
> object ('a)
> constraint 'a = < as_c : 'a; id : int; .. >
> method as_c : 'a
> method id : int
> end
> ================
>
> Why type 'c must have methods "as_c" and "id" ?
This may be a bit confusing, but the .. in your constraint on 'c means
that no actual subtyping will occur when you use this type as target.
Indeed, if the constraint was left unchanged, it would mean that by
choosing an arbitrary instance, you could use the as_c method to
convert an object of type "t a" to any "t".
Since no subtyping occurs, (self :> 'c) is just equivalent to
(self : 'c) (i.e. unify 'c with the type of self).
As a result, you get
object ('a)
...
method as_c : 'a
...
end
Jacques
next prev parent reply other threads:[~2009-04-09 10:13 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-04-09 8:42 Radzevich Belevich
2009-04-09 10:10 ` [Caml-list] " Radzevich Belevich
2009-04-09 10:13 ` Jacques Garrigue [this message]
2009-04-09 10:21 ` Radzevich Belevich
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=20090409.191306.169484516.garrigue@math.nagoya-u.ac.jp \
--to=garrigue@math.nagoya-u.ac.jp \
--cc=caml-list@inria.fr \
--cc=radzevich.belevich@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