什么是指标| dic是什么病| 四世同堂什么意思| 腺肌症是什么症状| 心脏有早搏吃什么药好| 禁忌是什么意思| 仓鼠用什么洗澡| 边界欠清是什么意思| 蜻蜓是什么生肖| 甲亢是什么病| 丝状疣是什么样子图片| 乳房胀痛挂什么科| 什么叫脂溢性脱发| 一点小事就暴躁的人是什么病| 四妙丸有什么功效与作用| 印度人口什么时候超过中国| 倩字五行属什么| 全科医生是什么意思| 小腹左边疼是什么原因| 痔疮术后吃什么恢复快| 苦瓜泡酒有什么功效和作用| 午夜是什么意思| 自提是什么意思| 幼小衔接班是什么意思| 为什么要吃叶酸| 夏天中暑吃什么药| 大健康是什么| 舌苔黄厚吃什么药| 亚米是什么意思| 付肾是什么药| 加油什么意思| 淡定从容是什么意思| 珍珠疹是什么| dumpling是什么意思| 寻麻疹看什么科| 弱精吃什么能提高活力| 黄瓜敷脸有什么功效| 名侦探柯南什么时候完结| 脚烧是什么原因| 井底之蛙是什么意思| 阴平阳秘是什么意思| 杰五行属什么| 尿道口流脓什么病| 什么蓝| 高同型半胱氨酸血症吃什么药| 支付宝提现是什么意思| 韩语欧巴是什么意思| 乳腺导管局限性扩张是什么意思| 什么是中产阶级| 植物神经功能紊乱吃什么药最好| 孕妇吃什么蔬菜对胎儿好| 天伦之乐是什么意思| 伊玛目是什么意思| 精液是什么味| 1977年属什么| 卖酒需要办理什么证| 雅五行属什么| 桃子像什么| 椒盐是什么调料| 康复治疗技术学什么| 庞统为什么要献连环计| 12月5号是什么星座| 螳螂捕蝉黄雀在后是什么生肖| 五月二十一是什么星座| 梦见捡了好多钱是什么预兆| 怀孕孕酮低吃什么补得快| 石女是什么意思啊| 螨虫长什么样子图片| 金火什么字| 家里为什么会有蜘蛛| live什么意思| 甘油三酯高吃什么食物好| 什么是数位| 女人吃什么新陈代谢快| 可心是什么意思| kenzo属于什么档次| 生理盐水敷脸有什么效果| noxa20是什么药| 藿香正气水有什么用| 为什么会莫名其妙流鼻血| c14呼气试验是检查什么的| 什么火没有烟| 吴亦凡为什么叫牛| 白细胞弱阳性是什么意思| 丁未五行属什么| 肺气肿吃什么食物好| 大腿根部疼痛是什么原因| 阑尾炎手术后可以吃什么水果| 喝什么水去火| 7月5日是什么星座| 梦见狗咬人是什么预兆| 耐力板是什么材质| 夏天吃什么养生| 三叉神经痛吃什么药效果好| 疖子用什么药膏最好| 女生胸部什么时候停止发育| 七月六号是什么星座| 腿抖是什么病的预兆| 彪马属于什么档次| 蜜蜡什么样的成色最好| 梦见很多狗是什么意思| 肛瘘挂什么科| 一树梨花压海棠什么意思| 农历六月十七是什么日子| 什么拼音怎么写| 内膜b型是什么意思啊| 从子是什么意思| 五液是指什么| 卒中是什么意思| 无公害什么意思| 脾胃不好吃什么水果好| 松鼠咬人后为什么会死| eicu是什么意思| 唇炎挂什么科| 肝不好挂什么科| 人鱼线是什么| 1955年属羊的是什么命| 车前草长什么样| 灰水是什么| 刀鱼和带鱼有什么区别| 双下肢静脉彩超主要检查什么| 9.11是什么星座| 猫薄荷是什么东西| pornhub是什么| 张一山和杨紫是什么关系| 为什么会得糖尿病| tt是什么| 男人尿多是什么原因| 人为什么有两个鼻孔| 肠胃炎能吃什么水果| 肺结节不能吃什么食物| 右边脸疼是什么原因| 18k黄金是什么意思| 什么地笑| 形而下是什么意思| 999足金是什么意思| 矽肺病是什么症状| 农业户口和非农业户口有什么区别| 健脾益气是什么意思| 仙逝是什么意思| 电起火用什么灭火器| 40而不惑是什么意思| 中国的国花是什么花| 散光看东西是什么样的| 女字五行属什么| 梦见小孩生病什么预兆| 星标朋友是什么意思| 夏朝前面是什么朝代| 小肚子一直疼是什么原因| pp材质是什么| 二尖瓣关闭不全是什么意思| pin是什么意思啊| 脚围指的是什么| 失眠挂什么科| 梦到被蜜蜂蛰是什么意思| 薷是什么意思| 天空中有什么| 什么虎不吃人| 胃疼有什么办法缓解| 打嗝多是什么原因| 八月初八是什么星座| 八月二十是什么星座| 出入是什么意思| 生殖疱疹吃什么药不复发| 良心是什么意思| 拉绿色大便是什么原因| 中午吃什么菜| 帕金森病是什么原因引起的| 平常吃什么补肾| 什么是血液病| 听佛歌有什么好处| 女性胆固醇高吃什么| 目是什么单位| ip指的是什么| 蚊虫叮咬红肿用什么药快速消肿| 心率过快吃什么药最好| 为什么全麻手术后不能睡觉| 补气补血吃什么药| 什么是放疗| 迂回什么意思| 边长是什么| 萎了是什么意思| 什么是打飞机| 男人有美人尖代表什么| 大姨妈来了可以吃什么水果| 吃什么孕酮值可以增高| 什么的花纹| 广州的市花是什么| 早上三点是什么时辰| 嗓子干疼吃什么药| 漫展是干什么的| 飞蚊症用什么药物治疗最好| 火腿肠炒什么好吃| 按摩椅什么品牌最好| 忌廉是什么东西| 皮脂腺痣是什么原因引起的| 喉咙有痰咳嗽是什么原因| jeans什么意思| 医调委是什么机构| 小便粉红色是什么原因| 溶肌症的症状是什么| 弼马温是什么意思| 白介素2是治疗什么病的| 1974年是什么命| 智齿发炎是什么原因| 夜间抽搐的原因是什么| 鼻子出血什么原因| 扌字旁的字和什么有关| 骨裂什么症状| 错构瘤是什么病| 口腔出血是什么病征兆| 宫颈机能不全是什么意思| 老鹰的绝症是什么| 奶油色是什么颜色| 09属什么生肖| 宽带m是什么意思| 违反禁令标志指示是什么意思| 6月17号是什么星座| 祥林嫂是什么样的人| 深海鱼油有什么作用| 出殡是什么意思| 花肠是母猪的什么部位| 三个鬼是什么字| 吃大虾不能吃什么| 尿痛吃什么药| 轱辘是什么意思| 夹心饼干是什么意思| 玄关挂什么装饰画好| 黑洞里面是什么| 梦到火是什么意思| 什么是肛漏| peace是什么牌子| l是什么码| 取经是什么意思| 甘草片不能和什么药一起吃| 嗪读什么| 草酸对人体有什么危害| 冬至吃什么馅的饺子| 高处不胜寒的胜是什么意思| 什么的李逵| lake是什么意思| 唇红齿白是什么生肖| 魔鬼城是什么地貌| 猫传腹是什么| 呼吸道感染吃什么药最好| 感冒了吃什么水果比较好| 转注是什么意思| 子子念什么| 护肝养肝吃什么药| 网络诈骗打什么电话| 蚰蜒吃什么| 刘禹锡是什么朝代的| 5月12日什么星座| 吃什么水果对皮肤好又美白| 吸毒是什么感觉| 胃不好应该吃什么| 花千骨最后结局是什么| 七上八下是什么生肖| 95是什么意思| 登高望远是什么生肖| pet一ct是一种什么检查| d表示什么| 龟头敏感吃什么药| 岁月不饶人是什么意思| 百度

北京4月上半月商品房网签骤减 业主主动调低报价

View Source

The Erlang Type Language

百度 王培安强调以老年人为重点人群提供互联网+医疗服务,大力支持智慧健康养老产业的发展。

Erlang is a dynamically typed language. Still, it comes with a notation for declaring sets of Erlang terms to form a particular type. This effectively forms specific subtypes of the set of all Erlang terms.

Subsequently, these types can be used to specify types of record fields and also the argument and return types of functions.

Type information can be used for the following:

  • To document function interfaces
  • To provide more information for bug detection tools, such as Dialyzer
  • To be leveraged by documentation tools, such as ExDoc or EDoc, for generating documentation

It is expected that the type language described in this section supersedes and replaces the purely comment-based @type and @spec declarations used by EDoc.

Types and their Syntax

Types describe sets of Erlang terms. Types consist of, and are built from, a set of predefined types, for example, integer/0, atom/0, and pid/0. Predefined types represent a typically infinite set of Erlang terms that belong to this type. For example, the type atom/0 denotes the set of all Erlang atoms.

For integers and atoms, it is allowed for singleton types; for example, the integers -1 and 42, or the atoms 'foo' and 'bar'. All other types are built using unions of either predefined types or singleton types. In a type union between a type and one of its subtypes, the subtype is absorbed by the supertype. Thus, the union is then treated as if the subtype was not a constituent of the union. For example, the type union:

atom() | 'bar' | integer() | 42

describes the same set of terms as the type union:

atom() | integer()

Because of subtype relations that exist between types, all types, except dynamic/0, form a lattice where the top-most element, any/0, denotes the set of all Erlang terms and the bottom-most element, none/0, denotes the empty set of terms.

To facilitate gradual typing of Erlang, the type dynamic/0 is provided. The type dynamic/0 represents a statically unknown type. It is similar to Any in Python, any in TypeScript and dynamic in Hack. any/0 and dynamic/0 interact with success typing the same way, so Dialyzer doesn't distinguish between them.

The set of predefined types and the syntax for types follows:

Type :: any()                 %% The top type, the set of all Erlang terms
      | none()                %% The bottom type, contains no terms
      | dynamic()
      | pid()
      | port()
      | reference()
      | []                    %% nil
      | Atom
      | Bitstring
      | float()
      | Fun
      | Integer
      | List
      | Map
      | Tuple
      | Union
      | UserDefined           %% described in Type Declarations of User-Defined Types

Atom :: atom()
      | Erlang_Atom           %% 'foo', 'bar', ...

Bitstring :: <<>>
           | <<_:M>>          %% M is an Integer_Value that evaluates to a positive integer
           | <<_:_*N>>        %% N is an Integer_Value that evaluates to a positive integer
           | <<_:M, _:_*N>>

Fun :: fun()                  %% any function
     | fun((...) -> Type)     %% any arity, returning Type
     | fun(() -> Type)
     | fun((TList) -> Type)

Integer :: integer()
         | Integer_Value
         | Integer_Value..Integer_Value      %% specifies an integer range

Integer_Value :: Erlang_Integer              %% ..., -1, 0, 1, ... 42 ...
               | Erlang_Character            %% $a, $b ...
               | Integer_Value BinaryOp Integer_Value
               | UnaryOp Integer_Value

BinaryOp :: '*' | 'div' | 'rem' | 'band' | '+' | '-' | 'bor' | 'bxor' | 'bsl' | 'bsr'

UnaryOp :: '+' | '-' | 'bnot'

List :: list(Type)                           %% Proper list ([]-terminated)
      | maybe_improper_list(Type1, Type2)    %% Type1=contents, Type2=termination
      | nonempty_improper_list(Type1, Type2) %% Type1 and Type2 as above
      | nonempty_list(Type)                  %% Proper non-empty list

Map :: #{}                                   %% denotes the empty map
     | #{AssociationList}

Tuple :: tuple()                             %% denotes a tuple of any size
       | {}
       | {TList}

AssociationList :: Association
                 | Association, AssociationList

Association :: Type := Type                  %% denotes a mandatory association
             | Type => Type                  %% denotes an optional association

TList :: Type
       | Type, TList

Union :: Type1 | Type2

Integer values are either integer or character literals or expressions consisting of possibly nested unary or binary operations that evaluate to an integer. Such expressions can also be used in bit strings and ranges.

The general form of bit strings is <<_:M, _:_*N>>, where M and N must evaluate to positive integers. It denotes a bit string that is M + (k*N) bits long (that is, a bit string that starts with M bits and continues with k segments of N bits each, where k is also a positive integer). The notations <<_:_*N>>, <<_:M>>, and <<>> are convenient shorthands for the cases that M or N, or both, are zero.

Because lists are commonly used, they have shorthand type notations. The types list(T) and nonempty_list(T) have the shorthands [T] and [T,...], respectively. The only difference between the two shorthands is that [T] can be an empty list but [T,...] cannot.

Notice that the shorthand for list/0, that is, the list of elements of unknown type, is [_] (or [any()]), not []. The notation [] specifies the singleton type for the empty list.

The general form of map types is #{AssociationList}. The key types in AssociationList are allowed to overlap, and if they do, the leftmost association takes precedence. A map association has a key in AssociationList if it belongs to this type. AssociationList can contain both mandatory (:=) and optional (=>) association types. If an association type is mandatory, an association with that type needs to be present. In the case of an optional association type it is not required for the key type to be present.

The notation #{} specifies the singleton type for the empty map. Note that this notation is not a shorthand for the map/0 type.

For convenience, the following types are also built-in. They can be thought as predefined aliases for the type unions also shown in the table.

Built-in typeDefined as
term/0any/0
binary/0<<_:_*8>>
nonempty_binary/0<<_:8, _:_*8>>
bitstring/0<<_:_*1>>
nonempty_bitstring/0<<_:1, _:_*1>>
boolean/0'false' | 'true'
byte/00..255
char/00..16#10ffff
nil/0[]
number/0integer/0 | float/0
list/0[any()]
maybe_improper_list/0maybe_improper_list(any(), any())
nonempty_list/0nonempty_list(any())
string/0[char()]
nonempty_string/0[char(),...]
iodata/0iolist() | binary()
iolist/0maybe_improper_list(byte() | binary() | iolist(), binary() | [])
map/0#{any() => any()}
function/0fun()
module/0atom/0
mfa/0{module(),atom(),arity()}
arity/00..255
identifier/0pid() | port() | reference()
node/0atom/0
timeout/0'infinity' | non_neg_integer()
no_return/0none/0

Table: Built-in types, predefined aliases

In addition, the following three built-in types exist and can be thought as defined below, though strictly their "type definition" is not valid syntax according to the type language defined above.

Built-in typeCan be thought defined by the syntax
non_neg_integer/00..
pos_integer/01..
neg_integer/0..-1

Table: Additional built-in types

Note

The following built-in list types also exist, but they are expected to be rarely used. Hence, they have long names:

nonempty_maybe_improper_list() :: nonempty_maybe_improper_list(any(), any())
nonempty_improper_list(Type1, Type2)
nonempty_maybe_improper_list(Type1, Type2)

where the last two types define the set of Erlang terms one would expect.

Also for convenience, record notation is allowed to be used. Records are shorthands for the corresponding tuples:

Record :: #Erlang_Atom{}
        | #Erlang_Atom{Fields}

Records are extended to possibly contain type information. This is described in Type Information in Record Declarations.

Redefining built-in types

Change

Starting from Erlang/OTP 26, it is permitted to define a type having the same name as a built-in type.

It is recommended to avoid deliberately reusing built-in names because it can be confusing. However, when an Erlang/OTP release introduces a new type, code that happened to define its own type having the same name will continue to work.

As an example, imagine that the Erlang/OTP 42 release introduces a new type gadget() defined like this:

-type gadget() :: {'gadget', reference()}.

Further imagine that some code has its own (different) definition of gadget(), for example:

-type gadget() :: #{}.

Since redefinitions are allowed, the code will still compile (but with a warning), and Dialyzer will not emit any additional warnings.

Type Declarations of User-Defined Types

As seen, the basic syntax of a type is an atom followed by closed parentheses. New types are declared using -type, -opaque, and -nominal attributes as in the following example:

-type my_struct_type() :: Type.
-opaque my_opaq_type() :: Type.
-nominal my_nominal_type() :: Type.

The type name is the atom my_struct_type, followed by parentheses. Type is a type as defined in the previous section. A current restriction is that Type can contain only predefined types, or user-defined types which are either of the following:

  • Module-local type, that is, with a definition that is present in the code of the module
  • Remote type, that is, type defined in, and exported by, other modules; more about this soon.

For module-local types, the restriction that their definition exists in the module is enforced by the compiler and results in a compilation error. (A similar restriction currently exists for records.)

Type declarations can also be parameterized by including type variables between the parentheses. The syntax of type variables is the same as Erlang variables, that is, starts with an upper-case letter. These variables is to appear on the RHS of the definition. A concrete example follows:

-type orddict(Key, Val) :: [{Key, Val}].

A module can export some types to declare that other modules are allowed to refer to them as remote types. This declaration has the following form:

-export_type([T1/A1, ..., Tk/Ak]).

Here the Tis are atoms (the name of the type) and the Ais are their arguments.

Example:

-export_type([my_struct_type/0, orddict/2]).

Assuming that these types are exported from module 'mod', you can refer to them from other modules using remote type expressions like the following:

mod:my_struct_type()
mod:orddict(atom(), term())

It is not allowed to refer to types that are not declared as exported.

Types declared as opaque represent sets of terms whose structure is not supposed to be visible from outside of their defining module. That is, only the module defining them is allowed to depend on their term structure. Consequently, such types do not make much sense as module local - module local types are not accessible by other modules anyway - and is always to be exported.

Change

Nominal types were introduced in Erlang/OTP 28.

Types declared as nominal are type-checked according to the user-defined names instead of their structure. That is, -nominal feet() :: integer() and -nominal meter() :: integer() are not the same type, while if -type is used it would be.

Read more on Opaques and Nominals

Type Information in Record Declarations

The types of record fields can be specified in the declaration of the record. The syntax for this is as follows:

-record(rec, {field1 :: Type1, field2, field3 :: Type3}).

For fields without type annotations, their type defaults to any(). That is, the previous example is a shorthand for the following:

-record(rec, {field1 :: Type1, field2 :: any(), field3 :: Type3}).

In the presence of initial values for fields, the type must be declared after the initialization, as follows:

-record(rec, {field1 = [] :: Type1, field2, field3 = 42 :: Type3}).

The initial values for fields are to be compatible with (that is, a member of) the corresponding types. This is checked by the compiler and results in a compilation error if a violation is detected.

Change

Before Erlang/OTP 19, for fields without initial values, the singleton type 'undefined' was added to all declared types. In other words, the following two record declarations had identical effects:

-record(rec, {f1 = 42 :: integer(),
             f2      :: float(),
             f3      :: 'a' | 'b'}).

-record(rec, {f1 = 42 :: integer(),
              f2      :: 'undefined' | float(),
              f3      :: 'undefined' | 'a' | 'b'}).

This is no longer the case. If you require 'undefined' in your record field type, you must explicitly add it to the typespec, as in the 2nd example.

Any record, containing type information or not, once defined, can be used as a type using the following syntax:

#rec{}

In addition, the record fields can be further specified when using a record type by adding type information about the field as follows:

#rec{some_field :: Type}

Any unspecified fields are assumed to have the type in the original record declaration.

Note

When records are used to create patterns for ETS and Mnesia match functions, Dialyzer may need some help not to emit bad warnings. For example:

-type height() :: pos_integer().
-record(person, {name :: string(), height :: height()}).

lookup(Name, Tab) ->
    ets:match_object(Tab, #person{name = Name, _ = '_'}).

Dialyzer will emit a warning since '_' is not in the type of record field height.

The recommended way of dealing with this is to declare the smallest record field types to accommodate all your needs, and then create refinements as needed. The modified example:

-record(person, {name :: string(), height :: height() | '_'}).

-type person() :: #person{height :: height()}.

In specifications and type declarations the type person() is to be preferred before #person{}.

Specifications for Functions

A specification (or contract) for a function is given using the -spec attribute. The general format is as follows:

-spec Function(ArgType1, ..., ArgTypeN) -> ReturnType.

An implementation of the function with the same name Function must exist in the current module, and the arity of the function must match the number of arguments, otherwise the compilation fails.

The following longer format with module name is also valid as long as Module is the name of the current module. This can be useful for documentation purposes.

-spec Module:Function(ArgType1, ..., ArgTypeN) -> ReturnType.

Also, for documentation purposes, argument names can be given:

-spec Function(ArgName1 :: Type1, ..., ArgNameN :: TypeN) -> RT.

A function specification can be overloaded. That is, it can have several types, separated by a semicolon (;). For example:

-spec foo(T1, T2) -> T3;
         (T4, T5) -> T6.

A current restriction, which currently results in a warning by Dialyzer, is that the domains of the argument types cannot overlap. For example, the following specification results in a warning:

-spec foo(pos_integer()) -> pos_integer();
         (integer()) -> integer().

Type variables can be used in specifications to specify relations for the input and output arguments of a function. For example, the following specification defines the type of a polymorphic identity function:

-spec id(X) -> X.

Notice that the above specification does not restrict the input and output type in any way. These types can be constrained by guard-like subtype constraints and provide bounded quantification:

-spec id(X) -> X when X :: tuple().

Currently, the :: constraint (read as "is a subtype of") is the only guard constraint that can be used in the when part of a -spec attribute.

Note

The above function specification uses multiple occurrences of the same type variable. That provides more type information than the following function specification, where the type variables are missing:

-spec id(tuple()) -> tuple().

The latter specification says that the function takes some tuple and returns some tuple. The specification with the X type variable specifies that the function takes a tuple and returns the same tuple.

However, it is up to the tools that process the specifications to choose whether to take this extra information into account or not.

The scope of a :: constraint is the (...) -> RetType specification after which it appears. To avoid confusion, it is suggested that different variables are used in different constituents of an overloaded contract, as shown in the following example:

-spec foo({X, integer()}) -> X when X :: atom();
         ([Y]) -> Y when Y :: number().

Some functions in Erlang are not meant to return; either because they define servers or because they are used to throw exceptions, as in the following function:

my_error(Err) -> throw({error, Err}).

For such functions, it is recommended to use the special no_return/0 type for their "return", through a contract of the following form:

-spec my_error(term()) -> no_return().

Note

Erlang uses the shorthand version _ as an anonymous type variable equivalent to term/0 or any/0. For example, the following function

-spec Function(string(), _) -> string().

is equivalent to:

-spec Function(string(), any()) -> string().
喝益生菌有什么好处 心慌是什么原因 腹腔肠系膜淋巴结是什么病 电视剧上星是什么意思 氟西汀什么意思
尿频是什么原因造成的 人生巅峰是什么意思 胃炎吃什么药 财鱼是什么鱼 什么粉一沾就痒还看不出来
太白金星是什么神 回流是什么意思 抽血前喝水有什么影响 dj管是什么 5个月宝宝吃什么辅食
枸杞泡水有什么功效 玻璃是什么做的 朝九晚五是什么意思 斯字五行属什么 星五行属性是什么
宛字五行属什么hcv7jop9ns1r.cn 国安局是什么单位xjhesheng.com 备孕喝豆浆有什么好处hcv7jop5ns2r.cn 五指毛桃不能和什么一起吃hcv8jop6ns9r.cn 让心归零是什么意思hcv8jop5ns8r.cn
生男生女取决于什么hcv7jop5ns6r.cn 煜怎么读音是什么意思aiwuzhiyu.com 喝酒前喝什么不容易醉hcv8jop1ns4r.cn 先知是什么意思hcv8jop4ns6r.cn 什么是锆石zsyouku.com
骨密度低吃什么药最快hcv9jop4ns8r.cn 木薯粉是什么东西hcv9jop6ns9r.cn 3月24日是什么星座hcv9jop3ns3r.cn 驾校体检都检查什么hcv7jop9ns7r.cn 来源朋友验证消息是什么意思travellingsim.com
矗读什么hcv9jop3ns8r.cn design是什么品牌shenchushe.com 明是什么生肖hcv8jop8ns9r.cn 子宫萎缩是什么原因hcv8jop6ns1r.cn 谷草转氨酶偏低是什么意思96micro.com
百度 技术支持:克隆侠蜘蛛池 www.kelongchi.com