You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
docs: Clarify important points about parametric types
ClosesJuliaLang#43811.
Removed some of the jargon and wikipedia links to make room for
a brief alternative `Point{T1,T2}` demonstration.
Shifted some paragraphs around to reflect their importance,
and changed the wording in some places.
This last point is *very* important: even though `Float64 <: Real` we **DO NOT** have `Point{Float64} <: Point{Real}`.
622
-
623
-
In other words, in the parlance of type theory, Julia's type parameters are *invariant*, rather
624
-
than being [covariant (or even contravariant)](https://en.wikipedia.org/wiki/Covariance_and_contravariance_%28computer_science%29). This is for practical reasons: while any instance
625
-
of `Point{Float64}` may conceptually be like an instance of `Point{Real}` as well, the two types
626
-
have different representations in memory:
615
+
In other words, in the parlance of type theory, Julia's type parameters are *invariant*.
616
+
This is for practical reasons: while any instance of `Point{Float64}` may conceptually be
617
+
like an instance of `Point{Real}` as well, the two types have different representations in memory:
627
618
628
619
* An instance of `Point{Float64}` can be represented compactly and efficiently as an immediate pair
629
620
of 64-bit values;
@@ -632,9 +623,9 @@ have different representations in memory:
632
623
practice an instance of `Point{Real}` must be represented as a pair of pointers to
633
624
individually allocated `Real` objects.
634
625
635
-
The efficiency gained by being able to store `Point{Float64}` objects with immediate values is
636
-
magnified enormously in the case of arrays: an `Array{Float64}` can be stored as a contiguous
637
-
memory block of 64-bit floating-point values, whereas an `Array{Real}` must be an array of pointers
626
+
The efficiency gained by imposing this restriction is magnified enormously in the case of arrays:
627
+
an `Array{Float64}` can be stored as a contiguous memory block of 64-bit floating-point values,
628
+
whereas an `Array{Real}` must be an array of pointers
638
629
to individually allocated [`Real`](@ref) objects -- which may well be
0 commit comments