Erlang型系统 [英] Erlang type system

查看:124
本文介绍了Erlang型系统的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在搜索网络寻找Erlang程序的各种打字实践,似乎有几个...虽然它有点难以找到一个固定的信息源
即Im寻找实用信息关于:

I've been scrounging around the web looking for various typing practices of Erlang programs and there seem to be a few... although its somewhat difficult to find a solid source of info namely Im looking for practical info about:

1。 -specs - 这个看起来很有吸引力。几个地方提到,在编译时检查具有关联的-specs指令的函数(正确的类型使用)...我似乎没有找到更多关于如何使用它的信息(使用哪种工具 - 透析器, TYPER?)。我真的很想创建一个小的解析器/代码,它将从

1.-specs - this one looks pretty attractive. a few places mention that the functions that have an associated -specs directive with it are checked at compile time(for correct type usage)... I cant seem to find more info on how to use it (which tool to use - Dialyzer,TypEr?). Im really eager to create a small parser/code-gen that would generate these "specs" from function declarations of the form

functionName(param1 :List, param2 :Tuple) -> ...

我还没有看到 -spec 支持抽象类型(用户声明类型 - Car类型 -

I have not seen if -spec supports abstract types (user declared types - "Car" type -

{car,{weight,_},{height,_},{maxSpeed,_}}

2。 -deftype 指令这里提到的

如果我可以开始打字,并在编译时检查它,Erlang将变得更加强大,上面提到的解析器/代码生成的运行时会产生

Erlang would become so much more powerful for me, if I could start typing things and have them be checked at compile time. The run-time the parser/code-gen I mentioned above would generate guard type checks in the output source-code.

推荐答案

更多有关此类型和规范属性的信息:

More info on the type and spec attributes here:

http://www.erlang.org/ eeps / eep-0008.html

透析器可用于检查它们(请参阅 dialyzer --help )。

Dialyzer can be used to check them (see dialyzer --help).

可以用Typer来生成m(见 typer --help )。

Typer can be used to generate them (see typer --help).

这篇关于Erlang型系统的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆