Merge pull request #76 from hynek/patch-1

Fix definition of contravariance
pull/77/head
Alexis Beingessner 6 years ago committed by GitHub
commit 7a93c089a8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -64,13 +64,13 @@ For instance `Vec` is a type constructor that takes a `T` and returns a
`Vec<T>`. `&` and `&mut` are type constructors that take two inputs: a `Vec<T>`. `&` and `&mut` are type constructors that take two inputs: a
lifetime, and a type to point to. lifetime, and a type to point to.
A type constructor's *variance* is how the subtyping of its inputs affects the A type constructor F's *variance* is how the subtyping of its inputs affects the
subtyping of its outputs. There are three kinds of variance in Rust: subtyping of its outputs. There are three kinds of variance in Rust:
* F is *covariant* over `T` if `T` being a subtype of `U` implies * F is *covariant* over `T` if `T` being a subtype of `U` implies
`F<T>` is a subtype of `F<U>` (subtyping "passes through") `F<T>` is a subtype of `F<U>` (subtyping "passes through")
* F is *contravariant* over `T` if `T` being a subtype of `U` implies * F is *contravariant* over `T` if `T` being a subtype of `U` implies
`F<U>` is a subtype of `F<U>` (subtyping is "inverted") `F<U>` is a subtype of `F<T>` (subtyping is "inverted")
* F is *invariant* over `T` otherwise (no subtyping relation can be derived) * F is *invariant* over `T` otherwise (no subtyping relation can be derived)
It should be noted that covariance is *far* more common and important than It should be noted that covariance is *far* more common and important than

Loading…
Cancel
Save