Erlang类型系统 [英] Erlang type system

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

问题描述

我一直在网上寻找Erlang程序的各种打字习惯,似乎有一些...虽然它有点难以找到一个坚实的信息来源
即Im寻找实用信息about:



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

形式的函数声明生成这些specs

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

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

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

2。 -deftype 指令此处提及



Erlang对我来说会变得更强大,如果我可以开始输入的东西,并在编译时检查它。运行时我上面提到的解析器/ code-gen

解决方案

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



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



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



Typer可用于生成它们(参见 typer-help )。 p>

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 - 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) -> ...

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

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

2.-deftype directive mentioned here

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 can be used to check them (see dialyzer --help).

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

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

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