财产.t对灵药有何意义?

时间:2017-12-15 08:37:11

标签: elixir

例如,在模块字符串的这种类型规范中:

@spec validate(String.t) :: {:atom}

这是什么意思?以及如何通过iex进行测试?

** (UndefinedFunctionError) function String.t/0 is undefined or private
    (elixir) String.t()

更新

看起来有些人没有看到通过iex测试哪种东西的必要性

对于我们其他正在学习灵药的人,我们可以这样做:

iex(8)> t String
@type t() :: binary()
@type codepoint() :: t()
@type grapheme() :: t()
@type pattern() :: t() | [t()] | :binary.cp()
iex(9)> t(String)
@type t() :: binary()
@type codepoint() :: t()
@type grapheme() :: t()
@type pattern() :: t() | [t()] | :binary.cp()

同样适用于.t

  

如果你想引用“字符串”类型(由...操作的那个)   在String模块中的函数),改为使用String.t / 0类型。

来源https://hexdocs.pm/elixir/typespecs.html#notes

1 个答案:

答案 0 :(得分:1)

这不是财产。基本上它是对“字符串”类型的引用,Elixir的String模块的函数正在使用它。要完全理解它,请阅读更多here

相关问题