官术网_书友最值得收藏!

Concrete and abstract types

In this hierarchy, some types, such as Number, Integer, and Signed, are abstract, which means that they have no concrete objects or values of their own. Instead, objects or values are of concrete types given by the result of applying typeof(value), such as Int8, Float64, and String. For example, the concrete type of the value 5 is Int64 given by typeof(5) (on a 64-bit machine). However, a value also has the type of all of its supertypes; for example, isa(5, Number) returns true (we introduced the isa function in the Types section of Chapter 2, Variables, Types, and Operations).

Concrete types have no subtypes and might only have abstract types as their supertypes. Schematically, we can differentiate them as follows:

An abstract type (such as Number and Real) is only a name that groups multiple subtypes together, but it can be used as a type annotation or used as a type in array literals. These types are the nodes in the type hierarchy that mainly serve to support the type tree. Also, note that an abstract type cannot have any fields.

The abstract type Any is the supertype of all types, and all the objects are also instances of Any.

At the other end is Union{}: this type has no values and no subtypes. All types are supertypes of Union{} , and no object is an instance of Union{}. It is unlikely that you will ever have to use this type. The Nothing type has one value called nothing.

When a function is only used for its side-effects, convention dictates that it returns nothing. We have seen this with the println function, where the printing is the side-effect, for instance:

x = println("hello") #> hello 
x == nothing #> true 
主站蜘蛛池模板: 合阳县| 瑞丽市| 沙湾县| 阳新县| 额济纳旗| 赣州市| 灵宝市| 富蕴县| 云霄县| 锦屏县| 板桥市| 上虞市| 新安县| 布拖县| 枝江市| 岑巩县| 大石桥市| 应城市| 黎平县| 通榆县| 济宁市| 晋江市| 普安县| 二连浩特市| 鲁山县| 哈巴河县| 长葛市| 聊城市| 宜城市| 赣州市| 樟树市| 建德市| 南充市| 龙口市| 西城区| 时尚| 水城县| 双鸭山市| 明星| 新郑市| 南木林县|