【发布时间】:2014-07-19 12:16:18
【问题描述】:
有没有办法在 Erlang 中检查变量是否属于自定义类型?
假设我在.hrl 文件中定义了一些记录和类型:
-record(custom_record, {
attr1 :: list(),
attr2 :: binary(),
attr3 :: tuple()
}).
-record(another_record, {
attr1 :: list(),
attr2 :: binary(),
}).
-type custom_record() :: #custom_record{}.
-type another_record() :: #another_record{}.
-type custom_records() :: custom_record() | another_record().
有没有一种简单的方法可以检查我的 Erlang 代码中的记录是否为 custom_record?像这样的东西会很好:
is_custom_type(CustomRecord, custom_records). %=> true
我查看了文档,没有看到任何内置函数可以做到这一点。
【问题讨论】:
标签: types erlang typechecking custom-type