types - Erlang 中非终止函数的类型

标签 types erlang dialyzer

我正在学习 Erlang 并尝试使用 Dialyzer 在可能的情况下获得最大的类型安全性。有一点我不明白:什么是非终止函数的类型以及如何在 -spec 中表示它.任何人都可以对此有所了解吗?

最佳答案

一个永远循环且永不终止的函数具有返回类型 no_return() . (该返回类型也用于总是抛出异常的函数,例如自定义错误函数。如果您没有指定该返回类型,Dialyzer 会告诉您该函数“没有本地返回”。)
这在 Types and Function Specifications 中提到Erlang引用手册的章节:

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) -> erlang:throw({error, Err}).

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

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

关于types - Erlang 中非终止函数的类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37184719/

相关文章:

date - 如何在 apache thrift 中表示日期类型

typescript - 如何定义一个类型,即从字符串中排除 'a' 的类型?

exception - 为什么我的变量在 erlang try 中不安全?

erlang - 在 Elixir 类型规范的类型定义中指定字符串值

Erlang:透析器对于一个大项目来说非常慢

c# - 检查两个泛型类型是否相等

带有 native mysql 驱动程序 ( mysqlnd ) 的 php pdo - 获取保留 native 列类型的数据

erlang - 如何在面向文档的系统中处理经过身份验证的用户对资源的访问?

database - 从不同节点访问分布式 mnesia 数据库

elixir - 如何在 Elixir 中指定具有可变数量参数的回调