Skip to content

Commit 3e5d2e5

Browse files
committed
docs: Apply review suggestions
1 parent 697ddc7 commit 3e5d2e5

File tree

1 file changed

+10
-14
lines changed

1 file changed

+10
-14
lines changed

doc/src/manual/types.md

+10-14
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@ Only by explicitly checking types, or when objects fail to support operations at
1414
are the types of any values ever restricted.
1515

1616
Julia's type system is dynamic, but gains some of the advantages of static type systems
17-
by allowing optional type annotations. This can be of great assistance
18-
in generating efficient code, but even more significantly, it allows method dispatch on the types
19-
of function arguments to be deeply integrated with the language. Method dispatch is explored in
20-
detail in the [Methods](@ref) section, but is rooted in the type system presented here.
17+
by allowing optional type annotations. Type annotations are important for defining efficient new data structures,
18+
can help enforce correctness and clarity, and can sometimes improve efficiency
19+
(although in many contexts the Julia compiler infers types automatically.
20+
Type annotations also play a central role in Julia because they control method dispatch:
21+
functions can be extended to new behaviours for different argument types.
22+
Method dispatch is explored in detail in the [Methods](@ref) section, but is rooted in the type system presented here.
2123

2224
All values in a Julia program belong to exactly one concrete type.
2325
All types belong to a single type tree, i.e. they are all at least related to the [`Any`](@ref) type.
@@ -46,18 +48,12 @@ kinds of programming, however, become clearer, simpler, faster and more robust w
4648
The default behavior in Julia when type annotations are omitted is to allow values to be of any type.
4749
When additional expressiveness is needed, however,
4850
it is easy to gradually introduce explicit annotations into previously "untyped" code.
49-
Adding annotations serves three primary purposes: to take advantage
51+
Adding annotations serves four primary purposes: to take advantage
5052
of Julia's powerful multiple-dispatch mechanism, to improve human readability,
51-
and to catch programmer errors.
53+
to catch programmer errors, and to assist the compiler (especially when defining new types).
5254

5355
The `::` operator can be used to attach type annotations to expressions and variables in programs.
5456
It is also used for type assertions in method signatures (see [Defining Methods](#Defining-Methods)).
55-
There are two primary reasons to use type annotations:
56-
57-
1. As an assertion to help confirm that your program works the way you expect, and
58-
2. To provide extra type information to the compiler, which can then improve performance in some
59-
cases.
60-
6157
When appended to an expression computing a value, the `::` operator is read as "is an instance
6258
of". It can be used anywhere to assert that the value of the expression on the left is an instance
6359
of the type on the right. When the type on the right is concrete, the value on the left must have
@@ -78,7 +74,7 @@ This allows a type assertion to be attached to any expression in-place.
7874
When the type on the right is concrete,
7975
the value on the left must have that type as its implementation.
8076
When the type is abstract,
81-
it suffices for the value to be implemented by a concrete type that is a subtype of the abstract type.
77+
it suffices for the value to have a concrete type that is a subtype of the abstract type.
8278
When appended to a variable on the left-hand side of an assignment, or as part of a `local` declaration,
8379
the `::` operator means something a bit different: it declares the variable to always have the
8480
specified type, like a type declaration in a statically-typed language such as C. Every value
@@ -605,7 +601,7 @@ julia> struct Point{T}
605601

606602
This declaration defines a new parametric type, `Point{T}`,
607603
holding two "coordinates" of the same type `T`.
608-
The parameter `T` is a placeholder, which will be replaced by a particular concrete type
604+
The parameter `T` is a placeholder, which will be replaced by a particular type
609605
when an instance of this type is created.
610606
Thus, this single declaration actually declares an unlimited number of types:
611607
`Point{Float64}`, `Point{AbstractString}`, `Point{Int64}`, etc.

0 commit comments

Comments
 (0)