2012-02-22 4 views

답변

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

네, 모두 내보낼 수 있으며 내보내기하지 않으면 차이가 없습니다.

+0

실제로 형식을 내 보내지 않으면 불투명으로 선언 할 때 의미가 없습니다. – aronisstav

+0

@aronisstav 그건 내가 말한 것 : 당신이 그것을 수출하지 않으면, 그들은 동일합니다. –

+0

'-type' 선언은 여러분이 export하지 않았을 때 여전히 유용합니다. ''불투명 '은 전혀 의미가 없습니다. – aronisstav

관련 문제