* [Caml-list] Variance constraint
@ 2001-03-20 12:52 Nicolas barnier
2001-03-20 14:03 ` Jacques Garrigue
0 siblings, 1 reply; 2+ messages in thread
From: Nicolas barnier @ 2001-03-20 12:52 UTC (permalink / raw)
To: ocaml
I found the doc quite elusive on the subtle + and - notations
for variance and contravariance constraints of abstract types.
Can someone points out a good reference with examples that
adresses this issue ? Maybe Jacques Garrigue ?
-- Nicolas
-------------------
To unsubscribe, mail caml-list-request@inria.fr. Archives: http://caml.inria.fr
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [Caml-list] Variance constraint
2001-03-20 12:52 [Caml-list] Variance constraint Nicolas barnier
@ 2001-03-20 14:03 ` Jacques Garrigue
0 siblings, 0 replies; 2+ messages in thread
From: Jacques Garrigue @ 2001-03-20 14:03 UTC (permalink / raw)
To: barnier; +Cc: caml-list
> I found the doc quite elusive on the subtle + and - notations
> for variance and contravariance constraints of abstract types.
> Can someone points out a good reference with examples that
> adresses this issue ? Maybe Jacques Garrigue ?
Sorry, there is nothing available currently.
You can find annotations in a few libraries: the Map module in the
standard library, the Raw module in LablGL, or the Gdk and Gtk modules
in LablGTK.
Basically, you normally only use annotations on abstract types (where
no definition is provided) to describe the expected behaviour of the
type with respect to subtyping.
For instance, an immutable container type (like lists) will have a
covariant type:
type (+'a) container
meaning that if s is a subtype of t then s container is a subtype of t
container. On the other hand an acceptor will have a contravariant
type:
type (-'a) acceptor
meaning that if s is a subtype of t then t acceptor is a subtype s
acceptor.
A type with no annotation is kept nonvariant, but there is no way to
express that a type is both covariant of contravariant (i.e. that both
subtypes and supertypes are ok): I don't really see any use for it...
For concrete or abbreviation types, variance is automatically
inferred, and variance annotations are only used to check that the
type really has the expected variance. In particular they do not
effectively restrict a type's variance.
Example
type (+'a) key = int
will be accepted, but key will actually be both covariant and
contraviant in 'a (which does not appear in the body).
Hope this helps. Should I add this to the manual ?
Jacques Garrigue
-------------------
To unsubscribe, mail caml-list-request@inria.fr. Archives: http://caml.inria.fr
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2001-03-20 14:01 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-03-20 12:52 [Caml-list] Variance constraint Nicolas barnier
2001-03-20 14:03 ` Jacques Garrigue
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox