- 浏览: 37656 次
- 来自: 深圳
文章分类
最新评论
-
ZacMa:
哈哈,突然感觉里面没怎么介绍,全是贴代码了
<8>redis及erl-redis阅读 -
惊涛翻案:
马博士,给我开课吧
<8>redis及erl-redis阅读
erlang是一种动态类型的语言(运行时才决定数据类型),可以自己声明一些数据类型
(1) 预定义类型
首先erlang自己有一套预定义的数据类型, 也可以有用户自己定义的类型,自己定义的类型都来源于这些预定义的类型的组合及类型定义的语法,
预定义类型:
Type :: any() %% The top type, the set of all Erlang terms.
| none() %% The bottom type, contains no terms.
| pid()
| port()
| reference()
| [] %% nil
| Atom
| Binary
| float()
| Fun
| Integer
| List
| Tuple
| Union
| UserDefined %% described in Section 2
Union :: Type1 | Type2
Atom :: atom()
| Erlang_Atom %% 'foo', 'bar', ...
Binary :: binary() %% <<_:_ * 8>>
| <<>>
| <<_:Erlang_Integer>> %% Base size
| <<_:_*Erlang_Integer>> %% Unit size
| <<_:Erlang_Integer, _:_*Erlang_Integer>>
Fun :: fun() %% any function
| fun((...) -> Type) %% any arity, returning Type
| fun(() -> Type)
| fun((TList) -> Type)
Integer :: integer()
| Erlang_Integer %% ..., -1, 0, 1, ... 42 ...
| Erlang_Integer..Erlang_Integer %% specifies an integer range
List :: list(Type) %% Proper list ([]-terminated)
| improper_list(Type1, Type2) %% Type1=contents, Type2=termination
| maybe_improper_list(Type1, Type2) %% Type1 and Type2 as above
Tuple :: tuple() %% stands for a tuple of any size
| {}
| {TList}
TList :: Type
| Type, TList
(2) 内置的一些类型:
一些联合类型的,是erlang系统已经定义好的,可以认为是自定义的, 当然erlang已经有的类型名字,我们自己不可以再次使用,编译时候会对这些类型进行检查:
Built-in type Stands for
term() any()
boolean() 'false' | 'true'
byte() 0..255
char() 0..16#10ffff
non_neg_integer() 0..
pos_integer() 1..
neg_integer() ..-1
number() integer() | float()
list() [any()]
maybe_improper_list() maybe_improper_list(any(), any())
maybe_improper_list(T) maybe_improper_list(T, any())
string() [char()]
nonempty_string() [char(),...]
iolist() maybe_improper_list(char() | binary() | iolist(), binary() | [])
module() atom()
mfa() {atom(),atom(),byte()}
node() atom()
timeout() 'infinity' | non_neg_integer()
no_return() none()
(3)用户自定义类型:
自己定义的类,必须引用已经有的预定义类型,或者已经定义过的类型,或者其他模块导出的类型,自定义类型的模板:-type my_struct_type() :: Type.
例如自己定一个int型,
-type int() :: integer().
这里integer() 必须是已经有的类型
(4)应用:
程序中的函数说明的通常用法,用这种方法更通用,结构固定,容易理解,
格式如下: -spec Module:Function(ArgType1, ..., ArgTypeN) -> ReturnType.
例如自己定义一个int(), 并且给test/1函数进行说明:
-module(test).
-compile(export_all).
-type int() :: integer().
<1> -spec test:test(integer()) -> integer().
<2> -spec test:test(A) -> A when
A::integer().
<3> -spec test:test(int()) -> int().
test(A) when is_integer(A) ->
A.
这三种方法都可以,方法<3>用了自己定义的类型int().
(1) 预定义类型
首先erlang自己有一套预定义的数据类型, 也可以有用户自己定义的类型,自己定义的类型都来源于这些预定义的类型的组合及类型定义的语法,
预定义类型:
Type :: any() %% The top type, the set of all Erlang terms.
| none() %% The bottom type, contains no terms.
| pid()
| port()
| reference()
| [] %% nil
| Atom
| Binary
| float()
| Fun
| Integer
| List
| Tuple
| Union
| UserDefined %% described in Section 2
Union :: Type1 | Type2
Atom :: atom()
| Erlang_Atom %% 'foo', 'bar', ...
Binary :: binary() %% <<_:_ * 8>>
| <<>>
| <<_:Erlang_Integer>> %% Base size
| <<_:_*Erlang_Integer>> %% Unit size
| <<_:Erlang_Integer, _:_*Erlang_Integer>>
Fun :: fun() %% any function
| fun((...) -> Type) %% any arity, returning Type
| fun(() -> Type)
| fun((TList) -> Type)
Integer :: integer()
| Erlang_Integer %% ..., -1, 0, 1, ... 42 ...
| Erlang_Integer..Erlang_Integer %% specifies an integer range
List :: list(Type) %% Proper list ([]-terminated)
| improper_list(Type1, Type2) %% Type1=contents, Type2=termination
| maybe_improper_list(Type1, Type2) %% Type1 and Type2 as above
Tuple :: tuple() %% stands for a tuple of any size
| {}
| {TList}
TList :: Type
| Type, TList
(2) 内置的一些类型:
一些联合类型的,是erlang系统已经定义好的,可以认为是自定义的, 当然erlang已经有的类型名字,我们自己不可以再次使用,编译时候会对这些类型进行检查:
Built-in type Stands for
term() any()
boolean() 'false' | 'true'
byte() 0..255
char() 0..16#10ffff
non_neg_integer() 0..
pos_integer() 1..
neg_integer() ..-1
number() integer() | float()
list() [any()]
maybe_improper_list() maybe_improper_list(any(), any())
maybe_improper_list(T) maybe_improper_list(T, any())
string() [char()]
nonempty_string() [char(),...]
iolist() maybe_improper_list(char() | binary() | iolist(), binary() | [])
module() atom()
mfa() {atom(),atom(),byte()}
node() atom()
timeout() 'infinity' | non_neg_integer()
no_return() none()
(3)用户自定义类型:
自己定义的类,必须引用已经有的预定义类型,或者已经定义过的类型,或者其他模块导出的类型,自定义类型的模板:-type my_struct_type() :: Type.
例如自己定一个int型,
-type int() :: integer().
这里integer() 必须是已经有的类型
(4)应用:
程序中的函数说明的通常用法,用这种方法更通用,结构固定,容易理解,
格式如下: -spec Module:Function(ArgType1, ..., ArgTypeN) -> ReturnType.
例如自己定义一个int(), 并且给test/1函数进行说明:
-module(test).
-compile(export_all).
-type int() :: integer().
<1> -spec test:test(integer()) -> integer().
<2> -spec test:test(A) -> A when
A::integer().
<3> -spec test:test(int()) -> int().
test(A) when is_integer(A) ->
A.
这三种方法都可以,方法<3>用了自己定义的类型int().
发表评论
-
erlang版本安装相关问题 <32>
2014-05-10 15:54 583<1> erlang R1603安装后,crytp ... -
关于iolist<30>
2014-01-15 10:42 590iolist是比较常用的数据结构. iolist的 ... -
erlang 字符编码 <29>
2014-01-14 16:31 1230用mochiweb通过网页发送中文到服务器,结果服务器显示乱码 ... -
<27>erlang record
2013-11-19 11:19 740平时总是忘记record的某些使用方法,每次使用都要翻文档, ... -
<26>io:format io_lib:format
2013-11-14 11:07 1277使用io_lib时候要注意参数,尤其是封装json串的时候,否 ... -
<24>用error_logger间隔记录日志
2013-10-22 16:09 630执行下面的代码 test:start(). test.erl ... -
<23>erlang 数据存储
2013-10-15 22:15 1624做为后端开发者,经常 ... -
<22> erlang中的数学计算函数相关
2013-10-10 10:34 15981. 幂函数 match:pow(m,n) 表示m的n次幂 ... -
<19>erlang中的时间,日期
2013-09-06 11:21 1164时间函数涉及的数据类型: DATA TYPES datetim ... -
<18>Efficient guide 之List handling
2013-08-31 18:45 6431 Deep and flat lists lists:fl ... -
<17>Efficiency Guide之Function
2013-08-27 22:30 5491. 函数模式匹配 模式匹配,在函数头,case和receiv ... -
<16>Efficiency Guide之Common Caveats
2013-08-11 11:07 771(1) ++ 如果做一个list的反转,不要这样, naiv ... -
<15> lists模块补充
2013-08-05 20:12 804%% 对list模块经常用到的进行补充 %% 1 对所有元素进 ... -
<15> lists模块解析和补充
2013-07-24 17:57 12%% 对list模块经常用到的进行补充 %% 1 对所有元素 ... -
<12>简述erlang的几种错误
2013-04-14 23:31 11571) badarg Bad argument. The ar ... -
<11>erlang中方便使用的模块和命令(2)
2013-04-06 22:33 758(1) 进程字典到底用不用,很多人推荐使用 http:// ... -
<9>rabbitmq网络层
2013-01-31 00:20 726抽离出了网络层, 逻辑层待以后研究 https://gith ... -
<8>redis及erl-redis阅读
2013-01-16 10:14 8221 redis的功能相当的强大,里面的发布订阅pub/su ... -
<7>pg2 分析
2012-12-08 13:42 1229网上看到erlang的pg2模块似乎没人推荐使用,但是还是有不 ... -
<6>error_logger 使用
2012-12-02 16:24 1429erlang中日志管理主要有error_loggger 模块, ...
相关推荐
NULL 博文链接:https://ZacMa.iteye.com/blog/1976833
Quasar 是一个 Java 库,提供了高性能、轻量级的线程,类似 Go 语言的 Channel,Erlang 语言的 Actor 和其他异步编程工具。 In Maven: <dependency> <groupId>co.paralleluniverse</groupId> <artifactId>quasar...
最低要求 快速开始编译项目: make要在/usr/local/bin安装生成的erlang_ls escript: make install命令行参数这些是可以提供给erlang_ls脚本的命令行参数: Usage: Erlang LS [-v] [-t [ < transport> ]] [-p [ < ...
Usage: emqtt_bench conn [--help < help> ] [-h [ < host> ]] [-p [ < port> ]] [-c [ < count> ]] [-n [ < startnumber> ]] [-i [ < interval> ]] [-u < username> ] [-P < password> ] [-k [ < keepalive
Scalang是消息传递和参与者库,它使Scala和Erlang应用程序可以轻松进行通信。 Scalang包含Erlang分布式节点协议的完整实现。 它提供了一个面向参与者的API ,该API可用于以惯用的,符合OTP的方式与Erlang节点进行...
米格尔用Erlang编写的另一个数据库迁移工具。它能做什么管理已应用/未应用的...]] [-a [<all>]] [-v [<version>]] [-h [<help>]] [command ...] -c, --config Config file -e, --env Env name in config [default: de
erlang 中文基础教程erlang 中文基础教程
对于t < lambda> 0是分布的速率参数。 在t >= lambda的情况下,未定义MGF,并且此模块返回NaN 。 安装 $ npm install distributions-erlang-mgf 要在浏览器中使用,请使用 。 用法 var mgf = require ( '...
Erlang是一个结构化,动态类型编程语言,内建并行计算支持。最初是由爱立信专门为通信应用设计的,比如控制交换机或者变换协议等,因此非常适 合于构建分布式,实时软并行计算系统。 使用Erlang编写出的应用运行时...
骡子郎运输 可以向 Erlang 节点发送消息和从 ... 快照构建在 Sonatype OSS 快照存储库中可用: < repository> < id>ossrh</ id> < url>https://oss.sonatype.org/content/repositories/snapshots</ url> < snapshots>
<<High Performance Erlang>>,英文,PDF格式
诊断以及调试生产环境中的Erlang 系统。在程序员学习新的语言和环境时,都需要一个摸索 阶段,也就是学会在社团的帮助下,脱离指南,解决实际问题。 本书假设读者精通基本的Erlang和OTP框架。在本书中,会对一些难以...
Erlang GOTONight 基础项目;... $> erl -pa ebin -boot start_sasl -name <YOUR>@<IP> -setcookie omnomnom > net_adm:ping('chatserver@<IP>'). > chat_client:start(chatroom:global_chatroom())
这是一个入门指导教你开始使用Erlang。...到或是在<Erlang参考手册>中找得到。 我也假设这不是你每一次接触计机算,而且了解编程的最基本的思想。不过不要着急,我并 不会假定你是一个有经验的开发人员。
erlang中文基础教程
rabbitmq和erlang,rabbitmq和erlang,rabbitmq和erlang,rabbitmq和erlang,rabbitmq和erlang,rabbitmq和erlang,rabbitmq和erlang,rabbitmq和erlang,rabbitmq和erlang
(494页带目录的高清扫描版) 这是一本讲解Erlang编程语言的入门指南,内容通俗...内容涉及模块、函数、类型、递归、错误和异常、常用数据结构、并行编程、多处理、OTP、事件处理,以及所有Erlang的重要特性和强大功能。
一个简单的模块系统,可轻松连接JavaScript和Erlang。 随附一些电池模块 入门 编译并启动一个shell: $ make $ make shell 确保已启动所有必需的应用程序,启动lib超级用户(请注意,这是一个单独的强制性步骤。...