Why does Dialyzer tell me that this funny contract has overlapping domains?

I am reading with interest the online book โ€œ I recognize you some erlang โ€ and try some exercises to test my understanding.

I made some changes using the example of fifo in the chapter Type specifications and Erlang , trying to define "typed_fifo (T)" (fifo, where all elements must be of the same type T)

My type specification:

-type typed_empty_fifo () :: {fifo, [], []}.

-type typed_nonempty_fifo (A) :: {fifo, nonempty_list (A), list (A)} | {fifo, [], notempty_list (A)}.

-type typed_fifo (A) :: typed_empty_fifo () | typed_nonempty_fifo (A).

and when I use it in the following spec function:

-spec empty (typed_empty_fifo ()) โ†’ true;

  (typed_nonempty_fifo(_)) -> false.

empty ({fifo, [], []}) โ†’ true;

empty ({fifo, A, B}), is_list (A), is_list (B) โ†’ false.

Dialyzer , - .

- , ?

, fifo, , , An Dialyzer , . , ( ) / .

, , bif/1, badarg!

23 > L = [1,2 | 3]. == > [1,2 | 3]

24 > is_list (L). == > true

25 > (L). == > :

 in function  length/1

    called as length([1,2|3])

+5
2

. , , Dialyzer , , . , : {fifo, nonempty_list(A), list(A)} | {fifo, [],nonempty_list(A) } "" {fifo, list(A), list(A)}, (3) (fifo). Dialyzer ( ), . .

is_list/1 , , , cons. is_list([1|2]) true.

, , case :

case is_proper_list(L) of
  true -> ...;
  false -> ...
end

is_proper_list([]) -> true;
is_proper_list([_|L]) -> is_proper_list(L);
is_proper_list(_) -> false.

. , (length(L) >= 0).

+3

, list :

1> L = [1,2|[3]].
[1,2,3]
2> is_list(L).
true
3> length(L).
3

, [Head|Tail] Tail list ( int).

0

All Articles