Skip to content

Commit 8809617

Browse files
mschauerfredrikekre
authored andcommitted
Doc-strings for some internals. (JuliaLang#23333)
* REPL-documentation for more internals. * Copy edit 'REPL-documentation for more internals.' * New section "Special Types"
1 parent 03c5d7d commit 8809617

File tree

2 files changed

+141
-3
lines changed

2 files changed

+141
-3
lines changed

base/docs/basedocs.jl

+127
Original file line numberDiff line numberDiff line change
@@ -1261,4 +1261,131 @@ available in the `.error` field.
12611261
"""
12621262
InitError
12631263

1264+
"""
1265+
Any::DataType
1266+
1267+
`Any` is the union of all types. It has the defining property `isa(x, Any) == true` for any `x`. `Any` therefore
1268+
describes the entire universe of possible values. For example `Integer` is a subset of `Any` that includes `Int`,
1269+
`Int8`, and other integer types.
1270+
"""
1271+
Any
1272+
1273+
"""
1274+
Union{}
1275+
1276+
`Union{}`, the empty [`Union`](@ref) of types, is the type that has no values. That is, it has the defining
1277+
property `isa(x, Union{}) == false` for any `x`. `Base.Bottom` is defined as its alias and the type of `Union{}`
1278+
is `Core.TypeofBottom`.
1279+
1280+
# Examples
1281+
```jldoctest
1282+
julia> isa(nothing, Union{})
1283+
false
1284+
```
1285+
"""
1286+
kw"Union{}", Base.Bottom
1287+
1288+
"""
1289+
Union{Types...}
1290+
1291+
A type union is an abstract type which includes all instances of any of its argument types. The empty
1292+
union [`Union{}`](@ref) is the bottom type of Julia.
1293+
1294+
# Examples
1295+
```jldoctest
1296+
julia> IntOrString = Union{Int,AbstractString}
1297+
Union{AbstractString, Int64}
1298+
1299+
julia> 1 :: IntOrString
1300+
1
1301+
1302+
julia> "Hello!" :: IntOrString
1303+
"Hello!"
1304+
1305+
julia> 1.0 :: IntOrString
1306+
ERROR: TypeError: typeassert: expected Union{AbstractString, Int64}, got Float64
1307+
```
1308+
"""
1309+
Union
1310+
1311+
1312+
"""
1313+
UnionAll
1314+
1315+
A union of types over all values of a type parameter. `UnionAll` is used to describe parametric types
1316+
where the values of some parameters are not known.
1317+
1318+
# Examples
1319+
```jldoctest
1320+
julia> typeof(Vector)
1321+
UnionAll
1322+
1323+
julia> typeof(Vector{Int})
1324+
DataType
1325+
```
1326+
"""
1327+
UnionAll
1328+
1329+
"""
1330+
::
1331+
1332+
With the `::`-operator type annotations are attached to expressions and variables in programs.
1333+
See the manual section on [Type Declarations](@ref).
1334+
1335+
Outside of declarations `::` is used to assert that expressions and variables in programs have a given type.
1336+
1337+
# Examples
1338+
```jldoctest
1339+
julia> (1+2)::AbstractFloat
1340+
ERROR: TypeError: typeassert: expected AbstractFloat, got Int64
1341+
1342+
julia> (1+2)::Int
1343+
3
1344+
```
1345+
"""
1346+
kw"::"
1347+
1348+
"""
1349+
Vararg{T,N}
1350+
1351+
The last parameter of a tuple type [`Tuple`](@ref) can be the special type `Vararg`, which denotes any
1352+
number of trailing elements. The type `Vararg{T,N}` corresponds to exactly `N` elements of type `T`.
1353+
`Vararg{T}` corresponds to zero or more elements of type `T`. `Vararg` tuple types are used to represent the
1354+
arguments accepted by varargs methods (see the section on [Varargs Functions](@ref) in the manual.)
1355+
1356+
# Examples
1357+
```jldoctest
1358+
julia> mytupletype = Tuple{AbstractString,Vararg{Int}}
1359+
Tuple{AbstractString,Vararg{Int64,N} where N}
1360+
1361+
julia> isa(("1",), mytupletype)
1362+
true
1363+
1364+
julia> isa(("1",1), mytupletype)
1365+
true
1366+
1367+
julia> isa(("1",1,2), mytupletype)
1368+
true
1369+
1370+
julia> isa(("1",1,2,3.0), mytupletype)
1371+
false
1372+
```
1373+
"""
1374+
Vararg
1375+
1376+
"""
1377+
Tuple{Types...}
1378+
1379+
Tuples are an abstraction of the arguments of a function – without the function itself. The salient aspects of
1380+
a function's arguments are their order and their types. Therefore a tuple type is similar to a parameterized
1381+
immutable type where each parameter is the type of one field. Tuple types may have any number of parameters.
1382+
1383+
Tuple types are covariant in their parameters: `Tuple{Int}` is a subtype of `Tuple{Any}`. Therefore `Tuple{Any}`
1384+
is considered an abstract type, and tuple types are only concrete if their parameters are. Tuples do not have
1385+
field names; fields are only accessed by index.
1386+
1387+
See the manual section on [Tuple Types](@ref).
1388+
"""
1389+
Tuple
1390+
12641391
end

doc/src/stdlib/base.md

+14-3
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ Base.widen
8383
Base.identity
8484
```
8585

86-
## Types
86+
## Dealing with Types
8787

8888
```@docs
8989
Base.supertype
@@ -109,11 +109,22 @@ Base.isbits
109109
Base.isleaftype
110110
Base.typejoin
111111
Base.typeintersect
112-
Base.Val
113-
Base.Enums.@enum
114112
Base.instances
115113
```
116114

115+
## Special Types
116+
117+
```@docs
118+
Core.Any
119+
Base.Enums.@enum
120+
Core.Union
121+
Union{}
122+
Core.UnionAll
123+
Core.Tuple
124+
Base.Val
125+
Core.Vararg
126+
```
127+
117128
## Generic Functions
118129

119130
```@docs

0 commit comments

Comments
 (0)