简体   繁体   English

为什么 OTP 中的类型规范会重复参数名称?

[英]Why do type specs in OTP repeat parameter names?

In type specs for the Erlang standard library, there are almost never any types in the spec until the when clause.在 Erlang 标准库的类型规范中,在when子句之前,规范中几乎没有任何类型。 For example, the spec for lists:member/2 is like this:例如, lists:member/2的规范是这样的:

-spec member(Elem, List) -> boolean() when
      Elem :: T,
      List :: [T],
      T :: term().

instead of:代替:

-spec member(Elem :: T, List :: [T]) -> boolean() when
      T :: term().

Is there a reason for this?是否有一个原因? Are these two styles equivalent from the dialyzer's point of view?从透析器的角度来看,这两个 styles 是否等效?

It is done that way because the documentation that is generated from the specs looks better if done like that.这样做是因为如果这样做,从规范生成的文档看起来会更好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM