在erlang中输入vs opaque指令

ego*_*or7 8 erlang

-opaque和之间有什么区别-type?我在erlang核心模块中看到了两者,但感觉不到区别.是否有可能同时使用-export_type它们?

Ale*_*nov 8

%% module1.erl
-export_type([my_tup1/0, my_tup2/0]).
-type my_tup1() :: {any(), any()}.
-opaque my_tup2() :: {any(), any()}.

%% module2.erl
-spec foo1(module1:my_tup1()) -> ok.
foo1({_, _}) -> ok. %% fine

-spec foo2(module1:my_tup2()) -> ok.
foo2({_, _}) -> ok. 
%% Dialyzer warning, because you are looking at 
%% the internal structure of a my_tup2() term.
%% If you defined the same function in the module module1, it wouldn't give a warning.

foo2(_) -> ok. %% no warning again.
Run Code Online (Sandbox Code Playgroud)

是的,您可以导出两者,如果您不导出它们,则没有区别.